fopen()打开words.txt文件读取内容
fgets()从文件中读取一行文本并将其放入字符数组word中
fgets()调用会保留每行之间用来断行的换行符,会被计为单词中的一个字符,所以将换行符替换为\0,表示字符串的结束
#import <Foundation/Foundation.h>
int main (int argc,const char * argv[])
{
FILE *wordFile =fopen ("/Users/niuniu/Desktop/words.rtf","r");
char word[100];
while(fgets(word,100, wordFile))
{
// strip off the trailing \n
word[strlen(word) -1] = '\0';
NSLog(@"%s is %lu characters long", word,strlen(word));
}
fclose (wordFile);
return (0);
}// main