Bug in fprintf/fscanf

Martin Laabs <[email protected]>
Newsgroups gmane.os.ecos.devel
Message-ID <[email protected]>
Hello,

could someone please verify the following bug I discovered. It seems that 
fprintf (or fputs) fails after a fscanf call. The second fprintf call 
however does work as expected.
I currently use the network as stream. Maybe this bug is because I use the 
fdopen function but at the moment I do not have an other working file 
descriptor.


Follwoing Code:

    term=fdopen(clntSock, "r+");
    assert(term!=0);

    while(1)
	{
	  fprintf(term, "Type a number\n");
	  diag_printf("fscanf %d\n", fscanf(term, "%d",&num));
	  diag_printf("fprintf1 %d\n",fprintf(term, "Number was %d\n",num));
   	  diag_printf("fprintf2 %d\n",fprintf(term, "Again - Number was 
%d\n",num));
	}

Produces following output (with Input of 8, 9 and 10):

Type a number
8
Again - Number was 8
Type a number
9
Again - Number was 9
Type a number
10
Again - Number was 10
Type a number


With diag output of:

fscanf 1
fprintf1 0
fprintf2 21
fscanf 1
fprintf1 0
fprintf2 21
fscanf 1
fprintf1 0
fprintf2 22

The complete code is available under http://pastebin.com/8iYVkAhz

Greetings,

  Martin Laabs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.