1757927326@qq.com 6 years ago
parent 40e3c01582
commit 496dc99015

@ -44,19 +44,19 @@ void main() /*
printf("\t\t\t0.退出\n\n"); /*退出*/ printf("\t\t\t0.退出\n\n"); /*退出*/
printf("\t\t\t请输入你的选择:"); printf("\t\t\t请输入你的选择:");
scanf("%d",&b); scanf("%d",&b);
switch(b) switch(b)
{ {
case 1:type();break; /*调用录入学生信息函数*/ case 1:type();break; /*调用录入学生信息函数*/
case 2:look();break; /*调用查看函数*/ case 2:look();break; /*调用查看函数*/
case 3:search_name();break; /*调用姓名查看学生信息函数*/ case 3:search_name();break; /*调用姓名查看学生信息函数*/
case 4:search_number();break; /*调用学号查看学生信息函数*/ case 4:search_number();break; /*调用学号查看学生信息函数*/
case 5:order();break; /*调用学号排序学生信息函数*/ case 5:order();break; /*调用学号排序学生信息函数*/
case 6:del();break;/*调用删除函数*/ case 6:del();break;/*调用删除函数*/
case 7:save();break;/*调用保存函数*/ case 7:save();break;/*调用保存函数*/
case 8:see();break;/*调用打开文件函数*/ case 8:see();break;/*调用打开文件函数*/
case 0:flag=1;break;/*退出SWITCH语句*/ case 0:flag=1;break;/*退出SWITCH语句*/
default :printf("错误!"); default :printf("错误!");
} }
if(flag) if(flag)
break; /*如果选择0就退出循环*/ break; /*如果选择0就退出循环*/
} }
@ -64,6 +64,7 @@ void main() /*
void type() /*定义录入学生信息函数*/ void type() /*定义录入学生信息函数*/
{ {
int i; /*定义局部变量*/ int i; /*定义局部变量*/
n=openl(); /*调用openl函数*/
printf("\t\t输出你想输入的学生信息个数:"); printf("\t\t输出你想输入的学生信息个数:");
scanf("%d",&n); scanf("%d",&n);
for(i=0;i<n;i++) for(i=0;i<n;i++)
@ -99,7 +100,7 @@ void save() /*
printf("不能打开文件!\n"); printf("不能打开文件!\n");
return; /*终止程序*/ return; /*终止程序*/
} }
for(i=0;i for(i=0;!feof(fp);i++)
if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1) if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
printf("文件写入错误\n"); printf("文件写入错误\n");
fclose(fp); /*关闭文件*/ fclose(fp); /*关闭文件*/
@ -124,10 +125,11 @@ void search_name() /*
{ {
int i; int i;
char name[20]; /*声明字符数组*/ char name[20]; /*声明字符数组*/
n=openl();
printf("\t\t\t请输入学生姓名:\n"); printf("\t\t\t请输入学生姓名:\n");
scanf("%s",name); scanf("%s",name);
printf("\t学号\t姓名\t性别\t年龄\t地址\t电话\tE-mail\t\t\t\n"); printf("\t学号\t姓名\t性别\t年龄\t地址\t电话\tE-mail\t\t\t\n");
for(i=0;i for(i=0;i<n;i++)
if(strcmp(stu[i].name,name)==0) /*将输入的姓名与结构体中的姓名进行比较*/ if(strcmp(stu[i].name,name)==0) /*将输入的姓名与结构体中的姓名进行比较*/
{ {
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",stu[i].num,stu[i].name, printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",stu[i].num,stu[i].name,
@ -140,10 +142,11 @@ void search_number() /*
{ {
int i; int i;
char number[15]; /*声明字符数组*/ char number[15]; /*声明字符数组*/
n=openl();
printf("\t\t\t请输入学号:\n"); printf("\t\t\t请输入学号:\n");
scanf("%s",number); scanf("%s",number);
printf("\t学号\t姓名\t性别\t年龄\t地址\t电话\tE-mail\t\t\t\n"); printf("\t学号\t姓名\t性别\t年龄\t地址\t电话\tE-mail\t\t\t\n");
for(i=0;i for(i=0;i<n;i++)
if(strcmp(stu[i].num,number)==0) /*将输入的学号与结构体中的学号进行比较*/ if(strcmp(stu[i].num,number)==0) /*将输入的学号与结构体中的学号进行比较*/
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",stu[i].num,stu[i].name, printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",stu[i].num,stu[i].name,
stu[i].sex,stu[i].age,stu[i].ad,stu[i].tel,stu[i].E,stu[i].year,stu[i].month,stu[i].day); stu[i].sex,stu[i].age,stu[i].ad,stu[i].tel,stu[i].E,stu[i].year,stu[i].month,stu[i].day);
@ -155,22 +158,22 @@ void order() /*
int i,j; int i,j;
char a; char a;
struct student temp; /*声明结构体变量*/ struct student temp; /*声明结构体变量*/
n=openl();
printf("\t学号\t姓名\t性别\t年龄\t地址\t电话\tE-mail\t\t\t\n"); printf("\t学号\t姓名\t性别\t年龄\t地址\t电话\tE-mail\t\t\t\n");
for(i=0;i for(i=0;i<n;i++)
{ {
for(j=i+1;j for(j=i+1;j<n-1;j++)
if(stu[i].sum if(stu[i].num>stu[j].num)
{ {
temp=stu[i]; temp=stu[i];
stu[i]= stu[j]; stu[i]= stu[j];
stu[j]=temp; stu[j]=temp;
} }
printf("%10s\t%s\t%2s\t%d\t%d\t%d\t%3.1f\t\t%6.1f\n",stu[i].num,stu[i].name, printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",stu[i].num,stu[i].name,
stu[i].sex,stu[i].english,stu[i].math,stu[i].chinese,stu[i].aver,stu[i].sum); stu[i].sex,stu[i].age,stu[i].ad,stu[i].tel,stu[i].E,stu[i].year,stu[i].month,stu[i].day);
} }
getch(); getch();
printf("是否保存?(y or n)"); printf("是否保存?(y or n)");
getchar();
scanf("%c",&a); scanf("%c",&a);
if(a=='y') /*是否保存排序后的文件*/ if(a=='y') /*是否保存排序后的文件*/
save(); save();
@ -183,10 +186,11 @@ void del() /*
int i; int i;
char a; char a;
char name[20]; char name[20];
n=openl();
printf("\t\t\t输入学生名字:\n"); printf("\t\t\t输入学生名字:\n");
scanf("%s",name); scanf("%s",name);
printf("\t学号\t姓名\t性别\t年龄\t地址\t电话\tE-mail\t\t\t\n"); printf("\t学号\t姓名\t性别\t年龄\t地址\t电话\tE-mail\t\t\t\n");
for(i=0;i for(i=0;i<n;i++)
if(strcmp(stu[i].name,name)==0) if(strcmp(stu[i].name,name)==0)
{ {
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",stu[i].num,stu[i].name, printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",stu[i].num,stu[i].name,
@ -197,14 +201,14 @@ void del() /*
scanf("%c",&a); scanf("%c",&a);
if(a=='y') /*是否删除该信息*/ if(a=='y') /*是否删除该信息*/
{ {
for(;i for(i=0;i<n;i++)
stu[i]=stu[i+1]; stu[i]=stu[i+1];
n=n-1; n=n-1;
printf("你已经删除信息"); printf("你已经删除信息");
} }
else else
printf("退出") printf("退出");
getch(); getchar();
} }
save(); save();
} }
@ -218,7 +222,7 @@ int openl() /*
exit(0); exit(0);
} }
for(i=0;!feof(fp);i++) for(i=0;!feof(fp);i++)
fread(&stu[i],sizeof(struct student),1,fp); fread(&stu[i],sizeof(struct student),1,fp);
fclose(fp); fclose(fp);
return(i-1); return(i-1);
} }
@ -230,74 +234,11 @@ void see() /*
printf("按任意键查看!\n"); printf("按任意键查看!\n");
getch(); getch();
printf("\t学号\t姓名\t性别\t年龄\t地址\t电话\tE-mail\t\t\t\n"); printf("\t学号\t姓名\t性别\t年龄\t地址\t电话\tE-mail\t\t\t\n");
for(i=0;i
if(strcmp(stu[i].name,name)==0)
{
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",stu[i].num,stu[i].name,stu[i].sex,stu[i].age,stu[i].ad,stu[i].tel,stu[i].E,stu[i].year,stu[i].month,stu[i].day);
getch();
printf("真的删除?(y or n)");
getchar();
scanf("%c",&a);
if(a=='y') /*是否删除该信息*/
{
for(;i
stu[i]=stu[i+1];
n=n-1;
printf("你已经删除信息");
}
else
printf("退出");
getch();
}
save();
}
int openl() /*定义打开文件函数*/
{
int i;
FILE *fp;
if((fp=fopen("student.txt","rb"))==NULL)
{
printf("Cannot open file.\n");
exit(0);
}
for(i=0;!feof(fp);i++)
fread(&stu[i],sizeof(struct student),1,fp);
fclose(fp);
return(i-1);
}
void see() /*打开并查看文件*/
{
int i;
n=openl();
printf("文件打开成功!\n");
printf("按任意键查看!\n");
getch();
printf("\t学号\t姓名\t性别\t年龄\t地址\t电话\tE-mail\t\t\t\n");
for(i=0;i<n;i++) for(i=0;i<n;i++)
{ {
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",stu[i].num,stu[i].name,
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",stu[i].num,stu[i].name, stu[i].sex,stu[i].age,stu[i].ad,stu[i].tel,stu[i].E,stu[i].year,stu[i].month,stu[i].day);
stu[i].sex,stu[i].age,stu[i].ad,stu[i].tel,stu[i].E,stu[i].year,stu[i].month,stu[i].day);
} }
printf("\n\n\n\t\t\t按任意键返回菜单"); printf("\n\n\n\t\t\t按任意键返回菜单");
getchar(); getchar();
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -83,6 +83,14 @@ LINK32=link.exe
# Begin Group "Source Files" # Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\1.C
# End Source File
# Begin Source File
SOURCE=..\..\h.c
# End Source File
# End Group # End Group
# Begin Group "Header Files" # Begin Group "Header Files"

Binary file not shown.

Binary file not shown.

@ -6,60 +6,40 @@
--------------------Configuration: LZT - Win32 Debug-------------------- --------------------Configuration: LZT - Win32 Debug--------------------
</h3> </h3>
<h3>Command Lines</h3> <h3>Command Lines</h3>
Creating temporary file "C:\Users\279800~1\AppData\Local\Temp\RSPCFE1.tmp" with contents Creating temporary file "C:\Users\279800~1\AppData\Local\Temp\RSP8AEB.tmp" with contents
[ [
/nologo /MLd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Fp"Debug/LZT.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c /nologo /MLd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Fp"Debug/LZT.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c
"E:\信息库\LZT\h.c" "F:\ÐÅÏ¢¿â\²âÊÔ\pmpe26s7b\LZT\1.C"
] ]
Creating command line "cl.exe @C:\Users\279800~1\AppData\Local\Temp\RSPCFE1.tmp" Creating command line "cl.exe @C:\Users\279800~1\AppData\Local\Temp\RSP8AEB.tmp"
Creating temporary file "C:\Users\279800~1\AppData\Local\Temp\RSP8AEC.tmp" with contents
[
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:yes /pdb:"Debug/LZT.pdb" /debug /machine:I386 /out:"Debug/LZT.exe" /pdbtype:sept
".\Debug\1.OBJ"
".\Debug\h.obj"
]
Creating command line "link.exe @C:\Users\279800~1\AppData\Local\Temp\RSP8AEC.tmp"
<h3>Output Window</h3> <h3>Output Window</h3>
Compiling... Compiling...
h.c 1.C
E:\信息库\LZT\h.c(102) : error C2143: syntax error : missing ';' before 'if' Linking...
E:\信息库\LZT\h.c(102) : error C2143: syntax error : missing ')' before 'if' h.obj : error LNK2005: _main already defined in 1.OBJ
E:\信息库\LZT\h.c(130) : error C2143: syntax error : missing ';' before 'if' h.obj : error LNK2005: _type already defined in 1.OBJ
E:\信息库\LZT\h.c(130) : error C2143: syntax error : missing ')' before 'if' h.obj : error LNK2005: _save already defined in 1.OBJ
E:\信息库\LZT\h.c(146) : error C2143: syntax error : missing ';' before 'if' h.obj : error LNK2005: _look already defined in 1.OBJ
E:\信息库\LZT\h.c(146) : error C2143: syntax error : missing ')' before 'if' h.obj : error LNK2005: _search_name already defined in 1.OBJ
E:\信息库\LZT\h.c(159) : error C2143: syntax error : missing ';' before '{' h.obj : error LNK2005: _search_number already defined in 1.OBJ
E:\信息库\LZT\h.c(159) : error C2143: syntax error : missing ')' before '{' h.obj : error LNK2005: _order already defined in 1.OBJ
E:\信息库\LZT\h.c(161) : error C2143: syntax error : missing ';' before 'if' h.obj : error LNK2005: _del already defined in 1.OBJ
E:\信息库\LZT\h.c(161) : error C2143: syntax error : missing ')' before 'if' h.obj : error LNK2005: _openl already defined in 1.OBJ
E:\信息库\LZT\h.c(161) : error C2039: 'sum' : is not a member of 'student' h.obj : error LNK2005: _see already defined in 1.OBJ
E:\信息库\LZT\h.c(15) : see declaration of 'student' Debug/LZT.exe : fatal error LNK1169: one or more multiply defined symbols found
E:\信息库\LZT\h.c(162) : error C2143: syntax error : missing ')' before '{' Error executing link.exe.
E:\信息库\LZT\h.c(168) : error C2039: 'english' : is not a member of 'student'
E:\信息库\LZT\h.c(15) : see declaration of 'student'
E:\信息库\LZT\h.c(168) : error C2039: 'math' : is not a member of 'student'
E:\信息库\LZT\h.c(15) : see declaration of 'student'
E:\信息库\LZT\h.c(168) : error C2039: 'chinese' : is not a member of 'student'
E:\信息库\LZT\h.c(15) : see declaration of 'student'
E:\信息库\LZT\h.c(168) : error C2039: 'aver' : is not a member of 'student'
E:\信息库\LZT\h.c(15) : see declaration of 'student'
E:\信息库\LZT\h.c(168) : error C2039: 'sum' : is not a member of 'student'
E:\信息库\LZT\h.c(15) : see declaration of 'student'
E:\信息库\LZT\h.c(189) : error C2143: syntax error : missing ';' before 'if'
E:\信息库\LZT\h.c(189) : error C2143: syntax error : missing ')' before 'if'
E:\信息库\LZT\h.c(200) : error C2146: syntax error : missing ';' before identifier 'stu'
E:\信息库\LZT\h.c(200) : error C2143: syntax error : missing ')' before ';'
E:\信息库\LZT\h.c(206) : error C2146: syntax error : missing ';' before identifier 'getch'
E:\信息库\LZT\h.c(249) : error C2143: syntax error : missing ';' before 'if'
E:\信息库\LZT\h.c(249) : error C2143: syntax error : missing ')' before 'if'
E:\信息库\LZT\h.c(249) : error C2065: 'name' : undeclared identifier
E:\信息库\LZT\h.c(249) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int '
E:\信息库\LZT\h.c(249) : warning C4024: 'strcmp' : different types for formal and actual parameter 2
E:\信息库\LZT\h.c(261) : error C2065: 'a' : undeclared identifier
E:\信息库\LZT\h.c(269) : error C2146: syntax error : missing ';' before identifier 'stu'
E:\信息库\LZT\h.c(269) : error C2143: syntax error : missing ')' before ';'
E:\信息库\LZT\h.c(291) : error C2084: function 'int __cdecl openl()' already has a body
E:\信息库\LZT\h.c(319) : error C2084: function 'void __cdecl see()' already has a body
E:\信息库\LZT\h.c(345) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
<h3>Results</h3> <h3>Results</h3>
h.obj - 31 error(s), 2 warning(s) LZT.exe - 11 error(s), 0 warning(s)
</pre> </pre>
</body> </body>
</html> </html>

Loading…
Cancel
Save