On Sun, Jun 8, 2008 at 7:47 PM, Bill Cunningham <[EMAIL PROTECTED]> wrote:

>  Can you show me an example in code where \0 can be added to the
> string taken and passed by fgets? I used strlen and it looks like
> fgets only adds one more character than entered and I'm guessing
> that's \n.

What fgets() does is either read n-1 characters (n being the length
you pass in) or \n. The \n will be included in the string, and fgets()
puts the null terminator and places everything in the buffer provided,
making it a valid C string. If you don't want the \n, you will need to
strip it out. If you want to see what is in the buffer after your call
to fgets(), I suggest running your program in a debugger and putting a
breakpoint on the line after the call to fgets() and examining what is
in memory.

-- Brett
------------------------------------------------------------
"In the rhythm of music a secret is hidden;
 If I were to divulge it, it would overturn the world."
 -- Jelaleddin Rumi

Reply via email to