Wednesday, October 16, 2013

objective-c of fget () reads the file, reads the contents of the less?

I'm learning objective-c based tutorial examples. Examples are as follows:
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:
2F reply quote:
see my blog post:
http://blog.csdn.net/yang3wei/article/details/7856273

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:
3rd Floor reply quote:
cited two floor Replies:
See my blog post:
http://blog.csdn.net/yang3wei/article/details/7856273

Saw, with my like ah

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:
5th Floor reply quote:
references 3F reply:

2nd Floor reply quote:
See my blog post:
http://blog.csdn.net/yang3wei/article/details/7856273

Saw, with my like ah

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?

Wording is no problem, I also use their brains and hands
Reply:
You when I was just out of college ah?
Xiangxunjiuxun?
5th Floor reply quote:
references 3F reply:

2nd Floor reply quote:
See my blog post:
http://blog.csdn.net/yang3wei/article/details/7856273

Saw, with my like ah

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:
landlord reply quote:
I'm learning objective-c based tutorial examples. Examples are as follows:
int main ()
{
FILE * wordFile = fopen ("D :/ word.txt", "r");
char word [100];
while (fgets (word, 100, wordFile))
{
word [strlen (word) - 1] = '\ 0';
......


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:
11th Floor reply quote:
C / C + + code

int main ()
{
FILE * wordFile = fopen ("D :/ word.txt", "r");
char word [100] = {0};
while (fgets (word, 100, wordFile))
{
/ / Word [strlen (word) - 1] = '\ 0';
NSLog (@ ......

Uh, so seemingly impossible
The result is commented out phrase, except for the last line, the length of each line +1'
Reply:
14th Floor reply quote:
hey, LZ adults, do you want it?

Carriage return line is character ah, but it is not visible. So calculated is the actual data length.

If you try to turn carriage return line filter, and there is nothing wrong:

According to the above reply, each row (except the last row) the last one should be '\ n';

word [strlen (word) - 1] = '\ 0';

The following sentence is not changed on it:

if ('\ n' == word [strlen ......

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:
15th Floor reply quote:
reply quote 14th floor:
Hey, LZ adults, do you want it?

Carriage return line is character ah, but it is not visible. So calculated is the actual data length.

If you try to turn carriage return line filter, and there is nothing wrong:

According to the above reply, each row (except the last row) the last one should be '\ n';

word [strlen (word) - 1] = '\ 0';

The following sentence is not changed on it:

if ('\ n' ......



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:
17th floor quote reply:
15th Floor reply quote:

Reply quote 14 Floor:
Hey, LZ adults, do you want it?

Carriage return line is character ah, but it is not visible. So calculated is the actual data length.

If you try to turn carriage return line filter, and there is nothing wrong:

According to the above reply, each row (except the last row) the last one should be '\ n';

word [strlen (word) - 1] = '\ 0';

The following sentence is not changed on ......


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