tags:

views:

242

answers:

1

I am trying to do something similar to this tutorial http://www.cprogramming.com/tutorial/c/lesson14.html

Where I get the title of the file to be opened, and the number of lines of that file to be printed at a time. I am having trouble on what I would put in my command line arguments. For example, do I need to put the name of my program in the command line argument?

"Assignment8_2" "testFile.rtf" "20"

Or do I only need the last two: "testFile.txt" "20"

Also, does the order matter in XCode when adding them with the "+" sign. I know the order will matter when we try to get the output (argv[1], argv[2], etc)

Also, where do I put the "testFile.rtf" in my file structure? Do I need to add it to my project? Put it in the same folder as my Executable?

I think I am doing something wrong because I currently have "testFile.txt" "5" as my arguments to XCode and when trying to print out argc, printf("%d", argc), I get nothing. I also try to print out argv[0], argv[1], argv[2], and I get: Assignment8_2(null)TERM_PROGRAM=Apple_terminal

A: 

From inside Xcode you only need the last two. Your best bet is to make the argument be the full path to the file, so you could do something like ${PROJECT_DIR}/test.rtf. The order matters; argv[1] will be the top argument, argv[2] the second, etc.

From the command line, the shell doesn't look in your current directory for commands, which is why it says command not found. Just do

./Assignment8_2 test.rtf 5

Putting the ./ in front makes the shell look in the current directory for the command.

Rudedog