Home > Back-end >  C language file management issues
C language file management issues

Time:06-02

Topic and I compiled program as shown in figure (5) please everybody see where the problem is how to thank you for

CodePudding user response:

refer to the original poster weixin_45812125 response:
title and I compiled program as shown in figure (5) please everybody see where the problem is how to thank you for

How to implement the sum of adding and output?

CodePudding user response:

Come and teach kids a great god

CodePudding user response:

While (... ) {
If (I=1) {.//I assignment 1,
Sum=number;
}
For (I=1; I<=30; I++) {.//what's the number plus 30 times?
Sum=sum + number;
}
}

Your track to track the change of the sum, shouldn't be more than playing a few lines of the debug adjustment printf here
The logical confusion

CodePudding user response:

I if the second for statement from I how to realize the loop is equal to 2

CodePudding user response:

Also what cycle? !
While reading itself is cycle data until the reading
While the former sum=0;
While the sum within +=number is finished,
Also what sort cycle

CodePudding user response:

In the end I use
While ((number=getw (f1))!=sum)
Printf (" % d ", number);
While ((sum=getw (f1))!=(EOF)
Printf (" % d ", sum);
The data output file
Can only display number does not display the sum is how to return a responsibility? Can you write like this?

CodePudding user response:


The change the disorderly

The sum and write half while
Int sum=0;
While ((number=getw (f1))!=(EOF) sum +=number;
Putw (sum, f1);
The fclose (f1)

The final output while don't change

CodePudding user response:

There's no way I tried is to copy the code
# include "stdio.h"
The main ()
{
The FILE * f1;
Int number, sum, I;
Printf (" the Contents of the DATA file \ n ");
F1=fopen (" DATA ", "w");
For (I=1; i<=30; I++)
{
The scanf (" % d ", & amp; Number);
If (number==1) break;
Putw (number, f1);
}
The fclose (f1);
F1=fopen (" DATA ", "a");
While ((number=getw (f1))!=(EOF)
{
The sum +=number;
}
Putw (sum, f1);
The fclose (f1);
F1=fopen (" DATA ", "r");
Printf (" \ nContenes of DATA file \ n ");
While ((number=getw (f1))!=(EOF)
Printf (" % d ", number);
The fclose (f1);
return 0;
}

CodePudding user response:

Sum=0 to where go to? Uninitialized
Before the third open, printf sum at a time and see how much is the
Then capture, there is a problem of data output

CodePudding user response:

Fun
references 9 floor response:
sum=0 to where go to? Uninitialized
Before the third open, printf sum at a time and see how much is the
Screenshots and then have a problem, the data output of

You haven't sleep please you I try again tomorrow morning

CodePudding user response:

After initialization printf sum has been 0 why not add

CodePudding user response:

CodePudding user response:

Oh, why is the file open in a way, automatic positioning to the tail of the file, so can't read out data
Should be a way of r + open the read and write operations

CodePudding user response:

Fun
reference 13 floor response:
oh, the reason was that the file open in a way, automatic positioning to the tail of the file, so can't read out data
Open the read and write operations should be r + way

Yeah, at the whole understand thank you very much

CodePudding user response:

I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10581430.html
I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10768339.html
  • Related