santosh wrote:
> Bill Cunningham wrote:
>
>> You code and the suggestions of others hav prompted me to check
>> fgets more closely. I guess it adds the newline. Now the \0 Is
>> added by my understanding by the compiler to a string and that's
>> the only time \0 is added.
>
> No. In this case, it's fgets that adds the terminating null
> character. The compiler is not the only entity that adds null
> characters. Several standard library functions also do this.
>
> In your case the problem is not the '\0' but the '\n' before it.
> Use strchr to find and remove it before doing the comparison
> with strcmp.
That's the slow way. Since fgets always ends operation when it
receives a '\n', any such character is at the end of the line
(otherwise it is a maximul line, and not complete). Therefore the
code:
lgh = strlen(s);
if ('\n' == s[lgh]) s[lgh] = '\0';
will always remove it. Or get my ggets routine at:
<http://cbfalconer.home.att.net/download/ggets.zip>
and always get complete lines with the terminal '\n' removed.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
--
Posted via a free Usenet account from
http://www.teranews.com