fscanf question

Gary L. Randolph randolph at ektools.UUCP
Wed Jan 3 06:22:00 AEST 1990


In article <6983 at ohstpy.mps.ohio-state.edu> SMITHJ at ohstpy.mps.ohio-state.edu writes:
/Sorry if this has come up before but I'm puzzled as to why the following code
/doesn't work.  The fprintf works fine but nothing is read in by the fscanf.
/#include <stdio>
***********>you mean stdio.h, right?
/
/int main(void)
/{
/       FILE *stream;
/       char outstr1[]="Trying", outstr2[]="Hoping";
/       char instr1[30], instr2[30];
/
/       stream = fopen("try2.gbk","w");
***********>In the 'real' world, of course, you check
that this worked.
/       fprintf(stream,"%-30s %-30s",outstr1,outstr2);
/       fclose(stream);
/
/       stream = fopen("try2.gbk","r");
/       fscanf(stream,"%-30s %-30s",instr1,instr2);
**********>the minus sign says left justify the *output*, this is all that
**********>is confusing your compiler. Take them out, and all is well.
/       fclose(stream);
/}

And I can't help it,

                WAR EAGLE!!!!!!!!!!!!!!!!!!!!!!!!

                        Gary



More information about the Comp.lang.c mailing list