#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
/* NSLog(@"the number is from 1 to 5");
for (int i=1; i<=5; i++) {
NSLog(@"%d\n",i);
}
*/
/*
int number=6;
for (int i=1; i<number; i++) {
NSLog(@"%d\n",i);
}
*/
/*
const char *words[3]={"aaa","bb","sfsdfsdf"};
int wordCount=3;
for (int i=0; i<wordCount; i++) {
NSLog(@"%s is %d characters long",words[i],strlen(words[i]));
}
*/
/**
//fopen()打开words.txt文件并读取文件内容,
//tmp是nuix的临时目录,这计算机重启时会被清空
FILE *wordFile=fopen("/tmp/word.txt", "r");
char word[100];
//fgets()从文件中读取一行并将其放入word,fgets()会保留分开每一行的换行符,我们不需要,我们将换行符替换为0,这表示字符串的结束。
while (fgets(word, 100, wordFile)) {
word[strlen(word)-1]='\0';
NSLog(@"%s is %d characters long",word,strlen(word));
}
//关闭文件
fclose(wordFile);
*/
//main()的argc参数,此参数保存启动参数的数目。因为程序名称常用作启动参数传递,所以argc值常为1或者更大。argc[0]保存程序名称
if(argc==1){
NSLog(@"you need to provide a file name");
return (1);
}
FILE *wordFile=fopen(argv[1], "r");
char word[100];
while (fgets(word, 100, wordFile)) {
word[strlen(word)-1]='\0';
NSLog(@"%s is %d characters long",word,strlen(word));
}
fclose(wordFile);
[pool drain];
return 0;
}