int main ()
{
FILE * wordFile = fopen ("D :/ word.txt", "r");
char word [100];
while (fgets (word, 100, wordFile))
{
word [strlen (word) - 1] = '\ 0';
NSLog (@ "% s is% d character long", word, strlen (word));
}
fclose (wordFile);
return 0;
}
word.txt line content is a string, the last line is the string "j"
But the output is not right "is 0 character long"
Why obviously have j, did not read?
Reply:
See my blog post:
http://blog.csdn.net/yang3wei/article/details/7856273
Reply:
Saw, with my like ah
Reply:
Ah ah ah ah ah ah, doing all these years of java, I did not expect from the new learn C, hey
To Pathwalker
Reply:
Bowen you what I get past the code inside a try, I guess the problem is that you have this wording,
Can not expect their little brains and hands do not move on the right problem to solve it?
Reply:
Wording is no problem, I also use their brains and hands
Reply:
You when I was just out of college ah?
Xiangxunjiuxun?
Reply:
LZ say is I do not know all the other words are not normally read, but only the last one J is not alone read.
If it is such a thing, it should be because
word [strlen (word) - 1] = '\ 0'; this sentence.
The last character changed to 0 that is '\ 0'
Reply:
The standard C library, there will be no functional problems.
fgets (word, 99, wordFile)
Reply:
I know what the problem
Because the last line with no line breaks, so
word [strlen (word) - 1] = '\ 0';
This sentence J to be deleted.
Could be a similar situation to the last row to add a line break it?
Reply:
int main ()
{
FILE * wordFile = fopen ("D :/ word.txt", "r");
char word [100] = {0};
while (fgets (word, 100, wordFile))
{
/ / Word [strlen (word) - 1] = '\ 0';
NSLog (@ "% s is% d character long", word, strlen (word));
memset (word, 0, 100);
}
fclose (wordFile);
return 0;
}
Reply:
Uh, so seemingly impossible
The result is commented out phrase, except for the last line, the length of each line +1'
Reply:
String aaaa, I hope length is 4 instead of 5.
I think a lot of work this year people should know.
Otherwise, users will think the length is wrong, you say?
Your answer was I denied, but also do not be so frantic personal attacks against me.
Are the issues discussed during the work time is your right, people are not allowed to say it?
Of course, if you did not work, I understand your
Reply:
word [strlen (word) - 1] = '\ 0'; been overwritten, and that this position is the last character
Reply:
String "aaaa", then the length is 4,
The problem is, the file in which each line of data is not "aaaa", but "aaaa \ n",,
Not yet understand?
Do not understand the words facie ASCII table ......
Reply:
Do you think the user know that the unseen '\ n' is what you
Does the user input "aaaa" out of the length is 5, and he will think it is normal you
I say that the user user, I do not understand is that you now
No comments:
Post a Comment