Using C programming language book but i'm stuck

Discussion in 'Mac Programming' started by thedon1, Aug 21, 2010.

  1. thedon1 macrumors 6502

    Joined:
    Jun 26, 2010
    #1
    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?
     
  2. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    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.
     
  3. Catfish_Man macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
  4. thedon1 thread starter macrumors 6502

    Joined:
    Jun 26, 2010
    #4
    Nice one guys, it was broken in the book so it threw me off.

    Thanks
     
  5. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    Location:
    Sailing beyond the sunset
    #5
  6. thedon1 thread starter macrumors 6502

    Joined:
    Jun 26, 2010
    #6
    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?
     
  7. lloyddean macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
    #7
    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.
     
  8. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #8
    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
     
  9. thedon1 thread starter macrumors 6502

    Joined:
    Jun 26, 2010
    #9
    Perfect, that worked, thanks
     
  10. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    Location:
    Sailing beyond the sunset
    #10
    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.
     
  11. thedon1 thread starter macrumors 6502

    Joined:
    Jun 26, 2010
    #11
    i'm assuming the .txt file is in the same folder as the program right?
     
  12. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    Location:
    Sailing beyond the sunset
    #12
    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.
     

Share This Page