So I have a file stream from a parent process to a child - and most of the time it works fine. However, when reading from it multiple times quickly, using ...
I'm using fgets to read in text from simple files such as txt files however I need the ability to jump back to previous lines. Is there anyway to do this ...
I want to read from a stdin stream. Is there any difference in using read() or fgets() to read from the stdin stream.
I am attaching the following two pieces of code ...
Thanks for your reply! Perhaps I should have clarified this a bit more. I don't want to read the entire string, that I can do. What I want to do is read a single character from it. I would have expected the output of puts(&buffer[1]) to be simply 'h', and nothing more, but this is not the case. Even putting the ...
If you want to read "any number" of characters, then you either have to start with a buffer big enough for "any number" (there is a limit to how much you can reasonably expect a human to type into a line, not to mention that MOST OS's have a limit to how long a line can be). Or you have to ...
> Why does this happen? Because you called scanf() to read some other input earlier on, and that left a stray '\n' in the input buffer - which is just what fgets() needs to exit "unexpectedly early" Avoid scanf altogether and read all input using fgets(). If appropriate, then use sscanf() on the buffer filled in by fgets() to extract the ...