fgets() and fopen() with "w"

V

vippstar

What happends if I try to read from a stream which has been opened
with "w" mode, either with fgets or some other function?
 
W

Walter Roberson

What happends if I try to read from a stream which has been opened
with "w" mode, either with fgets or some other function?

fgets, C89:

If a read error occurs during the operation, the array contents
are indeterminate and a null pointer is returned.

Some of the other functions return EOF instead of a null pointer,
or return an unusual count -- depends on the exact function.
 
V

vippstar

fgets, C89:

If a read error occurs during the operation, the array contents
are indeterminate and a null pointer is returned.

Some of the other functions return EOF instead of a null pointer,
or return an unusual count -- depends on the exact function.
So what happends is a read error and not undefined behavior.
Thanks for the quick response.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top