Pointless - because all you are doing is loading the data into one buffer, making minor amendments, then moving it to another buffer. You might as well write directly to the target buffer. I'd write an example, but Prelude's already done so.Originally posted by WaltP
I don't know about pointless. I keeps the input stream clean when more than string_length characters are entered. If you use the provided pointer, this call will only load the first string_length characters leaving the rest of the input in the stream. The next fgets() call will load the next portion of the input from the first fgets -- definitely not a good idea.
And dangerous? Why?
Dangerous - because of this:
In this case, the line:Code:#define BUFSIZ 512 /* copied from my stdio.h for clarity */ char buff; gstring (buff, sizeof(buff));
buffer[string_length - 1] = '\0';
writes to no-mans-land. Obviously we shouldn't write code like this, but in the defence of the programmer, I think it's safe to presume that if you pass a valid length indicator, the function shouldn't use it to access undefined memory addresses.