#include
#include
#include
#include
#include
#include
#include
# define MAXSIZE
Int main (void)
{
The FILE * fd.
Int I, size, k, num, len.
Char * buf.
Char buf_r [10], a [100].
Len=strlen (buf);
Printf (" * * * Welcome to the system of students' scores! * * * \ n \ n ");
Printf (" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf (" * * * * * * * * * * * * * * * * * * * * the Design by CBP * * * * * * * * * * * * * * * \ n ");
/* first calls the open function, and specify the corresponding permissions */
If ((fd=fopen ("/home/CBP/score. C ", "rw")) & lt; 0 {
Perror (" open ");
exit(1);
}
The else
Printf (" open file: score. C ");
If ((size=fread (buf_r, sizeof (char), 1, fd)) & lt; 0 {
Perror (" read: ");
exit(1);
}
The else
Printf (" number: % s \ n ", buf_r);
Num=atoi (buf_r);
for(i=0; i
for(i=0; i
{
Perror (" read: ");
exit(1);
}
The else {
A [I]=atoi (buf_r);
k=1;
Printf (" read from file: % d \ n ", a [I]);
Int num1=atoi (buf_r);
If (num1 & gt;
=90)Printf (" youxiu: % d \ n ", num1);
The else {the if (num1 & gt;
=80)Printf (" lianghao: % d \ n ", num1);
The else {the if (num1 & gt;
=70)Printf (" zhongdeng: % d \ n ", num1);
The else {the if (num1 & gt;=60)
Printf (" jige: % d \ n ", num1);
The else printf (" bujige: % d \ n ", num1); }}}}
}
If (fclose (fd) & lt; 0 {
Perror (" close, ");
exit(1);
}
The else
Printf (" Close score. C \ n ");
exit(0);
}
CodePudding user response:
/home/CBP/score. The c in Windows have this path and the file?if ((fd=fopen ("/home/CBP/score. C ", "rw")) & lt; 0 {
Perror (" open ");
exit(1);
}
This has a problem, fd should be compared and NULL,
As this place did not perform to the exit, in fact, because can't find file fd is NULL, but the NULL & lt; 0 does not satisfy, so there is no exit, directly behind the fd appear mistake,
Solution:
if ((fd=fopen ("/home/CBP/score. C ", "rw"))==NULL) {
Perror (" open ");
exit(1);
}
Under the Windows a try, see if I can run directly perror and exit (no/home/directory under Windows)
I need to know the difference between Windows and LINUX system, can't get the code to use, because there will be a transplant problem ~
CodePudding user response:
I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10581430.html