Home > Back-end >  C language homework assignments for help!!!!!!
C language homework assignments for help!!!!!!

Time:10-04

Write programs, from the keyboard input an integer in order 1234, one character at a time. A, a real number 5.6, with fprintf functions written int. TXT file
My classmate write code:
#include
#include
Int main ()
{
int a;
Char b;
Float c;
The FILE * fp.
The scanf (" % f, % d, % c ", & amp; A, & amp; B, & amp; C);
If ((fopen (" int. TXT ", "w"))==NULL)
{
Printf (" always open a file \ n ");
exit(0);
}
Fprintf (fp, "% d, % s, % f", a, b, c);
fclose(fp);
return 0;
}
Finally execution can only create a file, but the file in blank,
According to the online classes I write:
#include
#include
Int main ()
{
Int a, b;
Char STR [20], [20] s.
Float x, y;
The FILE * fp.
The scanf (" % d % s % f ", & amp; A, STR, & amp; X);
If ((fp=fopen (" int. TXT ", "w"))==NULL)
{
Printf (" always open a file \ n ");
exit(0);
}
Fprintf (fp, "% d % % s. 1 f", a, STR, x);
fclose(fp);
return 0;
}
The last execution success
Help:
These two code, the difference is?
Why the first can't perform a success?
Really don't understand to seek help from bosses

CodePudding user response:

He didn't seem to point to any first of fp

CodePudding user response:

 fprintf (fp, "% d, % s, % f", a, b, c); 

To:
 fprintf (fp, "% f, % d, % c, a, b, c); 


Don't you didn't find the first program, so the return value of fopen assigned to fp?

CodePudding user response:

You are the first code
The scanf (" % f, % d, % c ", & amp; A, & amp; B, & amp; C);
This way, the scanf function using commas, also want to enter a comma when input

CodePudding user response:

reference 2 building self-confidence boy reply:
 fprintf (fp, "% d, % s, % f", a, b, c); 

To:
 fprintf (fp, "% f, % d, % c, a, b, c); 


Don't you didn't find the first program, so the return value of fopen assigned to fp?

He sent me is that he change the code before, I'm dizzy

CodePudding user response:

reference 2 building self-confidence boy reply:
 fprintf (fp, "% d, % s, % f", a, b, c); 

To:
 fprintf (fp, "% f, % d, % c, a, b, c); 


Don't you didn't find the first program, so the return value of fopen assigned to fp?

My classmate sent me is that he modify the code before,,, I changed, but still blank

CodePudding user response:

The scanf (" % f, % d, % c ", & amp; A, & amp; B, & amp; C);
If (( fp= fopen (" int. TXT ", "w"))==NULL)

In front of the person is less, the fp=, didn't put the fp assignment, the back of the fprintf (fp,,,,, fp is a what the devil is unknown, so can't write a success
  • Related