/*
* 统计文本文件中单词的长度
*
*/
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
FILE *wordFile = fopen("words.txt","r");
char word[100];
while (fgets(word,100,wordFile)) {
//换行符修改为 '\0'
word[strlen(word)-1] = '\0';
NSLog(@"%s is %d characters long",
word,strlen(word));
}
fclose(wordFile);
return 0;
}
如何自动复制文件words.txt到目标目录:
在Targets下面,右键项目名,Add New build Phase -> New Files Phase
目标选为Executables,然后把words.txt拖到刚才建立的"copy FIles (1)" build Phase
如何给调试项目添加命令行参数:
在Executables下双击程序名,在Arguments下点击加号,输入启动参数。