Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

thedon1

macrumors 6502a
Original poster
Jun 26, 2010
529
73
I'm using the C programming language book by Keringhan and Ritchie.

I'm on page 20, 1.5.4, section on word counting.

It introduces a symbol which it says means "or."

It looks like 2 vertical brackets, one stacked on another.

How do i write this on my keyboard?

Any other considerations i need to make?
 
This is two pipe characters. |, I don't have a real keyboard and type by touch, but it's near the return key. Might be the shifted character on a key.

-Lee

Edit: Shifted backslash, \. looks like it's just above return on the US layout. Might vary slightly on a laptop. It might be shown "broken" half way up. Sorry for the US-centric reply; if you use another layout, say which.
 
Nice one guys, it was broken in the book so it threw me off.

Thanks
 
One more question about this chapter.

I have written the code for the examples on word counting, line counting ad arrays in chapter one but how do i get the program to actually count something?

I open the console and go to build and run just like the other examples but i don't know what input the code is looking for.

Are these not practical examples or am i missing something?
 
Select "Edit Active Executable" at the bottom of the "Project" menu will bring up an "Info" window.

Select the second view-tab titled "Arguments".

Click the "+" button at the bottom of the "Info" window to add parameters that wold be passed on the command line.
 
I think this example reads from stdin until it hits EOF. You can enter text at the console, then enter ctrl+d to end input. This is one of the reasons I think an IDE can hinder learning, having to figure out the intricacies of the IDE while trying to figure out the language.

-Lee
 
I think this example reads from stdin until it hits EOF. You can enter text at the console, then enter ctrl+d to end input. This is one of the reasons I think an IDE can hinder learning, having to figure out the intricacies of the IDE while trying to figure out the language.

-Lee

Perfect, that worked, thanks
 
You can also copy and paste text into Xcode's console window. You still have to type control-D manually.

If this seems like a useless way to run programs, it's because the original code is intended for use on a command-line, where you can redirect input and output to any file with simple notations. If the program's name is 'woc', examples might be:
Code:
woc <anyfile.txt
ifconfig | woc
ftpCount=`woc </etc/ftpusers`
The first counts the words in anyfile.txt. The second counts the words in the output of the 'ifconfig' command. The third counts words in /etc/ftpusers and assigns that count to the shell variable ftpCount.
 
You can also copy and paste text into Xcode's console window. You still have to type control-D manually.

If this seems like a useless way to run programs, it's because the original code is intended for use on a command-line, where you can redirect input and output to any file with simple notations. If the program's name is 'woc', examples might be:
Code:
woc <anyfile.txt
ifconfig | woc
ftpCount=`woc </etc/ftpusers`
The first counts the words in anyfile.txt. The second counts the words in the output of the 'ifconfig' command. The third counts words in /etc/ftpusers and assigns that count to the shell variable ftpCount.

i'm assuming the .txt file is in the same folder as the program right?
 
i'm assuming the .txt file is in the same folder as the program right?

Or 'woc' is in a directory listed in PATH, which is a list of directories to search for commands.

The plain unadorned pathname "anypath.txt" always refers to a file in the current working directory. It doesn't start with "/", so that means it's a relative pathname, not an absolute pathname. And it contains no other /-separated names, so it's not referring to any other directories.
http://en.wikipedia.org/wiki/Working_directory
http://en.wikipedia.org/wiki/Path_(computing)


As far as I know, you can't use any of the examples I gave in Xcode. Its console window is not a command-line shell.

Your Executable for the Xcode project lets you control the working directory when you run the program. Double click the Executable and you'll see a tab that lets you change the environment.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.