已知在tmp路径下有一个words.txt (tmp/words.txt)文本内容:
Joe-Bob "Handyman" Brown
Jacksonville "Sly" Murphy
Shinara Bain
George "Guitar" BooksJoe-Bob "Handyman" Brown建立一个程序,其主函数体是:
FILE *wordFile=fopen("tmp/words.txt","r");
char word[100];
while(fgets(word,100,wordFile)){
word[strlen(word)-1]='0';
NSlog(@"%s is %d characters long",word,strlen(word));运行的结果是:
Joe-Bob "Handyman" Brown is 24 characters long
Jacksonville "Sly" Murphy is 25 characters long
Shinara Bain is 12 characters long
George "Guitar" Books is 21 characters long===============>我的疑问是:while(fgets(word,100,wordFile))里的fget(word,100,wordFile),作用不是直接读取全部的99个字符吗?但按照结果,原理却好像是fget函数按一行一行地读取?这是怎么解释呢?
Joe-Bob "Handyman" Brown
Jacksonville "Sly" Murphy
Shinara Bain
George "Guitar" BooksJoe-Bob "Handyman" Brown建立一个程序,其主函数体是:
FILE *wordFile=fopen("tmp/words.txt","r");
char word[100];
while(fgets(word,100,wordFile)){
word[strlen(word)-1]='0';
NSlog(@"%s is %d characters long",word,strlen(word));运行的结果是:
Joe-Bob "Handyman" Brown is 24 characters long
Jacksonville "Sly" Murphy is 25 characters long
Shinara Bain is 12 characters long
George "Guitar" Books is 21 characters long===============>我的疑问是:while(fgets(word,100,wordFile))里的fget(word,100,wordFile),作用不是直接读取全部的99个字符吗?但按照结果,原理却好像是fget函数按一行一行地读取?这是怎么解释呢?
解决方案 »
- cocos2d-x中播放音乐
- cocos2d-x里的CCCamera不同,显示效果就不一样
- 横竖屏切换时界面整体会往home键方向平移
- 学ios系统开发的人很少吧
- Voip后台实现过程中的问题,底层用sip的库,求支援求帮助求分析解决
- 在cell 里 写button 为什么 没有点击效果 一点反映没有??
- viewcontroller控件的显示,位置问题
- 请问设置根视图控制器起什么作用?
- 怎么给图片命名呢
- UITabBarController启动后只能显示一个标签
- 如何下载sample code,例如CrashLanding?
- 我有一个iphone的项目是在MAC下用Xcode开发的,由于一些特殊原因,现在需要在linux上继续开发,请问我该如何继续这个项目的开发和编译?
Get string from streamReads characters from stream and stores them as a C string into str until (num-1) characters have been read or either a newline or a the End-of-File is reached, whichever comes first.
A newline character makes fgets stop reading, but it is considered a valid character and therefore it is included in the string copied to str.
A null character is automatically appended in str after the characters read to signal the end of the C string.Parameters
str
Pointer to an array of chars where the string read is stored.
num
Maximum number of characters to be read (including the final null-character). Usually, the length of the array passed as str is used.
stream
Pointer to a FILE object that identifies the stream where characters are read from.
To read from the standard input, stdin can be used for this parameter.