Xcode & passing command line arguments

Posted by Brisco on Stack Overflow See other posts from Stack Overflow or by Brisco
Published on 2009-08-19T23:54:03Z Indexed on 2010/05/24 16:51 UTC
Read the original article Hit count: 396

Filed under:
|
|

I just started working with C & Xcode and I've run into a little difficulty.

All I want to do is read a file from the command line and see the output in the terminal. I think my problem lies with the path to the file that I want to read in. I'm using a Mac and the file is on my desktop, so the path should be Users/myName/Desktop/words.txt. Is this correct?

This is my code:

#import <Foundation/Foundation.h>

int main (int argc, const char* argv[]){

    if(argc == 1){
        NSLog(@" you must pass at least one arguement");
        return 1;
    }
    NSLog(@"russ");
    FILE*  wordFile = fopen(argv[1] , "r");
    char word[100];

    while (fgets(word,100,wordFile)) {

        NSLog(@" %s is %d chars long", word,strlen(word));

    }

    fclose(wordFile);
    return 0;

}//main

© Stack Overflow or respective owner

Related posts about c

    Related posts about osx