开发者

differences in size of two

i am having a directory which contains 4 files namely 1.c,2.c,3.c and 4.c.i am reading the file names present under this directory by using readdir system call which returns to some structure variable namely myStruct.

2)I am having another open file namely a.txt file which contains file names like 1.c,2.c,3.c,4.c etc...

My intention is to compare the files present in a.txt with the files presen in the directory(just the na开发者_如何学Gome comparison is enough..not checking its contents).

when i do the comparison,even though the names present in the directory matches with those present in the a.txt file,they dont show equal comparison and then when i printed the lenghths they are unequal.

Can anyone please let me know any solution to this problem

thanks maddy


When you read from the file, there is an extra null character at the end of the line you have read, so the comparison will show that they are unequal. So after reading the line, trim off the \n and then try.

EDIT

This discussion tells you about how to trim whitespaces in a string using C - Painless way to trim leading/trailing whitespace in C?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜