When I open a file, the file is valid (passes if (!file)). But when I use it with fgets, fgets fails. When I called ferror the return value is 32. I looked that up and it means broken pipe. What does this mean and how could I fix it?

This is my code:

FILE *f = fopen ("q1/config.cfg","w");
int i;
while (fgets(buff, 1024, f))
	if (buff[0] != '/' && buff[1] != '/')
		Cmd_ExecuteString (buff);
i = ferror (f);

Recommended Answers

All 4 Replies

So buff is 1024 characters long?

char buff[1024];

yes.

Your reading from a stream that's opened for writing..

oh wow, i feel like an idiot.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.