为什么WIN_TC编译下列程序一直调用不了子程序?
这几天写了个程序、用WIN-TC一直调不通,希望有高手帮我看看哈!写了两天的程序、一直想不通为什么调用不了子程序希望有高手为我解惑!
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#define HEAD1 "------------------------------------STUDENT------------------------------------\n"
#define HEAD2 "︳学号 ︳姓名 ︳语文 ︳数学 ︳英语 ︳总分 ︳平均分 ︳名次 ︳\n "
#define HEAD3 "︳---------- ︳--------------- ︳----- ︳----- ︳----- ︳----- ︳----- ︳----- ︳"
#define FORMAT "︳%-10s ︳%-15s ︳%4d ︳%4d ︳%4d ︳%4d ︳% .2f ︳%4d ︳\n "
#define DATA p->data.num,p->data.name,p->data.egrade,p->data.mgrade,p->data.cgrade,p->data.total,p->data.ave,p->data.mici
#define END "_______________________________________________________________________________\n"
int saveflag=0;
typedef struct student
{
char num[10];
char name[15];
int cgrade;
int mgrade;
int egrade;
int total;
float ave;
int mici;
};
typedef struct node
{
struct student data;
struct node *next;
}Node,*Link;
void menu()/*主菜单*/
{
system("cls");
textcolor(10);
gotoxy(10,5);
cprintf("=====>The Students' Grade Management System \n");
gotoxy(10,8);
cprintf("************************Menu************************\n");
gotoxy(10,9);
cprintf("* 1 input record 2 delete record*\n");
gotoxy(10,10);
cprintf("* 3 search record 4 modify record*\n");
gotoxy(10,11);
cprintf("* 5 insert record 6 count record*\n");
gotoxy(10,12);
cprintf("* 7 sort record 8 save record*\n");
gotoxy(10,13);
cprintf("* 9 display record 0 quit system*\n");
gotoxy(10,14);
cprintf("************************Menu************************\n");
}
void Disp(Link l)/*表格形式显示记录*/
{
Node *p;
p=l->next;
if (!p)
{
printf("\n========>Not student record!");
getchar();
return;
}
printf("\n\n");
printhead();/*输出表格头部*/
while(p)
{
printdata(p);
p=p->next;
printf(HEAD3);
}
getchar();
}
void printhead()/*表头格式化输出*/
{
printf(HEAD1);
printf(HEAD2);
printf(HEAD3);
}
void printdata(Node *pp)/*格式化输出表中数据*/
{
Node *p;
p=pp;
printf(FORMAT,DATA);
}
void Wrong() /*输出按键错误信息*/
{
printf("\n\n\n\n==========>Error:input has wrong!press any key to continue:");
getchar();
}
void Nofind()/*输出未查找到此学生的信息*/
{
printf("\n========> NOT find this student!\n");
}
Node *Locate(Link l,char findmess[],char nameornum[])/*记录查找定位*/
{
Node *r;
if(strcmp(nameornum,"num")==0)/*按学号查询*/
{
r=l->next;
while(r)
{
if(strcmp(r->data.num,findmess)==0)/*若找到findmess值的学号*/
return r;
r=l->next;
}
}
else
if(strcmp(nameornum,"name")==0)/*按姓名查询*/
{
r=l->next;
while(r)
{
if(strcmp(r->data.name,findmess)==0)/*若找到findmess值的学生姓名*/
return r;
r=r->next;
}
}
return 0; /*若未找到,返回一个空指针*/
}
/*输入字符串,并进行长度验证*/
void stringinput(char *t,int lens,char *notice)/*格式化输入数据*/
{
char n[255];
do{
printf(notice);
scanf("%s",&n);
if(strlen(n)>lens)
printf("\n exceed the required length!\n");
}
while(strlen(n)>lens);
strcpy(t,n);
}
int numberinput(char *notice)/*输入分数,0到100*/
{
int t=0;
do{
printf(notice);
scanf("%d",&t);
if(t>100||t<0)
printf("\n score must in [0,100]!\n");
}
while(t>100||t<0);
return t;
}
void Add(Link l)/*增加学生记录*/
{
Node *p,*r,*s;
char ch;
int flag=0;
int num[10];
r=l;
s=l->next;
system("cls");
Disp(l);
while(r->next!=NULL)
r=r->next;
while(1)
{
while(1)
{
stringinput(num,10,"input number(press '0' return menu):");
flag=0;
if(strcmp(num,"0")==0);
{
return;
}
s=l->next;
while(s)
{
if(strcmp(s->data.num,num)==0)
{
flag=1;
break;
}
s=s->next;
}
if(flag==1)
{
getchar();
printf("=====>The number %s is not existing,try again?(Y/N):",num);
scanf("%c",&ch);
if(ch=='y'||ch=='Y')
continue;
else
return;
}
else
{break;}
}
p=(Node *)malloc(sizeof(Node));
if(!p)
{
printf("\n allocate memory failure ");
return;
}
strcpy(p->data.num,num);
stringinput(p->data.name,15,"Name:");
p->data.cgrade=numberinput("C language Score[0-100]:");
p->data.mgrade=numberinput("C Math Score[0-100]:");
p->data.egrade=numberinput("C English Score[0-100]:");
p->data.total=p->data.egrade+p->data.cgrade+p->data.mgrade;
p->data.ave=(float)(p->data.total/3);
p->data.mici=0;
p->next=NULL;
r->next=p;
r=p;
saveflag=1;
}
return;
}
void Qur(Link l)/*按照学号或者姓名查询学生记录*/
{
int select;
char searchinput[20];
Node *p;
if(!l->next)
{
system("cls");
printf("\n======>No student record\n");
getchar();
return;
}
system("cls");
printf("\n ======>1 Search by number ======>2 Search by name\n");
printf(" please choice[1,2]:");
scanf("%d",&select);
if(select==1)
{
stringinput(searchinput,10,"input the existing student number:");
p=Locate(l,searchinput,"num");
if(p)
{
printhead();
printdata(p);
printf(END);
printf("press any key to return");
getchar();
}
else
Nofind();
getchar();
}
else
if(select==2)
{
stringinput(searchinput,15,"input the existing student name:");
p=Locate(l,searchinput,"name");
if(p)
{
printhead();
printdata(p);
printf(END);
printf("press any key return");
getchar();
}
else
Nofind();
getchar();
}
else
Wrong();
getchar();
}
void Del(Link l)/*删除学生记录*/
{
int sel;
Node *p,*r;
char findmess[20];
if(!l->next)
{
system("cls");
printf("\n======>No student record!\n");
getchar();
return;
}
system("cls");
Disp(l);
printf("\n =======>1 Delete by number ======>2 Delete by name\n");
printf(" please choice[1,2]:");
scanf("%d",&sel);
if(sel==1)
{
stringinput(findmess,10,"input the existing student number:");
p=Locate(l,findmess,"num");
if(p)
{
r=l;
while(r->next!=p)
r=r->next;
r->next=p->next;
free(p);
printf("\n=====>delete success!\n");
getchar();
saveflag=1;
}
else
Nofind();
getchar();
}
if(sel==2)
{
stringinput(findmess,15,"input the existing student name");
p=Locate(l,findmess,"name");
if(p)
{
r=l;
while(r->next!=p)
r=r->next;
r->next=p->next;
free(p);
printf("\n=======>delete success!\n");
gechar();
saveflag=1;
}
else
Nofind();
getchar();
}
else
Wrong();
getchar();
}
void Modify(Link l)/*修改学生记录*/
{
Node *p;
char findmess[20];
if(!l->next)
{
system("cls");
printf("\n======>No student record!\n");
getchar();
return;
}
system("cls");
printf("modify student recorder");
Disp(l);
stringinput(findmess,10,"input the existing student number:");
p=Locate(l,findmess,"num");
if(p)
{
printf("Number:%s,\n",p->data.num);
printf("Name:%s,",p->data.name);
stringinput(p->data.name,15,"input new name:");
printf("C language score:%d,",p->data.cgrade);
p->data.cgrade=numberinput("C language score[0-100]:");
printf("Math score:%d,",p->data.mgrade);
p->data.mgrade=numberinput("Math score[0-100]:");
printf("English score:%d,",p->data.egrade);
p->data.egrade=numberinput("English score[0-100]");
p->data.total=p->data.egrade+p->data.cgrade+p->data.mgrade;
p->data.ave=(float)(p->data.total/3);
p->data.mici=0;
printf("\n======>modify success!\n");
Disp(l);
saveflag=1;
}
else
Nofind();
getchar();
}
void Insert(Link l)/*插入学生记录*/
{
Link p,v,newinfo;
char ch,num[10],s[10];
int flag=0;
v=l->next;
system("cls");
Disp(l);
while(1)
{
stringinput(s,10,"please input insert location after the Number:");
flag=0;
v=l->next;
while(v)
{
if(strcmp(v->data.num,num)==0)
{
flag=1;
break;
}
v=v->next;
}
if(flag==1)
break;
else
{
gechar();
printf("\n======>The number %s is not existing,try again?(y/n):",s);
scanf("%c",&ch);
if(ch=='y'||ch=='Y')
{
continue;
}
else
{
return;
}
}
}
stringinput(num,10,"input new student Number:");
v=l->next;
while(v)
{
if(strcmp(v->data.num,s)==0)
{
printf("\n======>Sorry,the new number : '%s'is existing!\n",num);
printhead();
printdata(v);
printf("\n");
getchar();
return;
}
v=v->next;
}
newinfo=(Node *)malloc(sizeof(Node));
if(!newinfo)
{
printf("\n allocate memoy failure");
return;
}
strcpy(newinfo->data.num,num);
stringinput(newinfo->data.name,15,"Name:");
newinfo->data.cgrade=numberinput("C language scoe[0-100]:");
newinfo->data.mgrade=numberinput("Math scoe[0-100]:");
newinfo->data.egrade=numberinput("Eenglish scoe[0-100]:");
newinfo->data.total=newinfo->data.egrade+newinfo->data.cgrade+newinfo->data.mgrade;
newinfo->data.ave=(float)(newinfo->data.total/3);
newinfo->data.mici=0;
newinfo->next=NULL;
saveflag=1;
p=l->next;
while(1)
{
if(strcmp(p->data.num,s)==0)
{
newinfo->next=p->next;
p->next=newinfo;
break;
}
p=p->next;
}
Disp(l);
printf("\n\n");
getchar();
}
void Tongji(Link l)/*统计学生记录*/
{
Node *pm,*pe,*pc,*pt;
Node *r=l->next;
int countc=0,countm=0,counte=0;
if(!r)
{
system("cls");
printf("\n======>Not student record!\n");
getchar();
return;
}
system("cls");
Disp(l);
pm=pe=pc=pt=r;
while(r)
{
if(r->data.cgrade<60) countc++;
if(r->data.mgrade<60) countm++;
if(r->data.egrade<60) counte++;
if(r->data.cgrade>=pc->data.cgrade) pc=r;
if(r->data.mgrade>=pm->data.mgrade) pm=r;
if(r->data.egrade>=pe->data.egrade) pe=r;
if(r->data.total>=pt->data.total) pt=r;
r=r->next;
printf("\n-----------the Tongji result----------------------------------\n");
printf("C Language<60:%d(ren)\n",countc);
printf("Math <60:%d(ren)\n",countm);
printf("English <60:%d(ren)\n",counte);
printf("----------------------------------------------------------------\n");
printf("The highest student by total scroe name:%s total score:%d\n",pt->data.name,pt->data.total);
printf("The highest student by English score name:%s total score:%d\n",pe->data.name,pe->data.egrade);
printf("The highest student by Math score name:%s total score:%d\n",pm->data.name,pm->data.mgrade);
printf("The highest student by C score name:%s total score:%d\n",pc->data.name,pc->data.cgrade);
printf("\n\npress any key to return");
getchar();
}
}
void Sort(Link l)/*排序学生记录,用的是插入法进行排序*/
{
Link ll;
Node *p,*rr,*s;
int i=0;
if(l->next==NULL)
{
system("cls");
printf("\n======>Not student record!\n");
getchar();
return;
}
ll=(Node*)malloc(sizeof(Node));
if(!ll)
{
printf("\n allocate memory failure ");
return;
}
ll->next=NULL;
system("cls");
Disp(l);
p=l->next;
while(p)
{
s=(Node*)malloc(sizeof(Node));
if(!s)
{
printf("\n allocate memory failure" );
return;
}
s->data=p->data;
s->next=NULL;
rr=ll;
while(rr->next!=NULL && rr->next->data.total>=p->data.total)
{
rr=rr->next;
}
if(rr->next==NULL)
rr->next=s;
else
{
s->next=rr->next;
rr->next=s;
}
p=p->next;
}
l->next=ll->next;
p=l->next;
while(p!=NULL);
{
i++;
p->data.mici=i;
p=p->next;
}
Disp(l);
saveflag=1;
printf("\n ======>sort complete!\n");
}
void Save(Link l)/*保存学生记录到d盘*/
{
FILE* fp;
Node *p;
int count=0;
fp=fopen("d:\\student","wb");
if(fp==NULL)
{
printf("\n======>open file error!\n");
getchar();
return;
}
p=l->next;
while(p)
{
if(fwrite(p,sizeof(Node),1,fp)==1)
{
p=p->next;
count++;
}
else
{
break;
}
}
if(count>0)
{
getchar();
printf("\n\n\n\n\n======>save file complete,total saved's record number is:%d\n",count);
getchar();
saveflag=0;
}
else
{
system("cls");
printf("the current link is empty,no student record is saved!\\n");
getchar();
}
fclose(fp);
}
void main()
{
Link l;
FILE *fp;
int select;
char ch;
int count=0;
Node *p, *r;
l=(Node *)malloc(sizeof(Node));
if(!l)
{
printf("\n allocate memory failure\n");
return ;
}
l->next=NULL;
r=l;
fp=fopen("D:\\student","ab+");
if(fp==NULL)
{
printf("\n======>打开文件失败!\n");
exit(0);
}
while(!feof(fp))
{
p=(Node *)malloc(sizeof(Node));
if(!p)
{
printf("memory allocate failure\n");
exit(0);
}
if(fread(p,sizeof(Node),1,fp)==1)
{
p->next=NULL;
r->next=p;
r=p;
count++;
}
}
fclose(fp);
printf("\n=====>open file sucess,the total records number is :%d.\n",count);
menu();
while(1)
{
system("cls");
menu();
p=r;
printf("\n====>Please Enter your choice(0~9):");
scanf("%d",&select);
if(select==0)
{
if(saveflag==1)
{
printf("\n====>Whether save the modified record to file?(Y/N):");
scanf("%c",&ch);
if(ch=='Y'||ch=='y')
Save(l);
}
printf("\n=====>Thank you for useness!");
gechar();
break;
}
switch(select)
{
case 1: Add(l);break;
case 2: Del(l);break;
case 3: Qur(l);break;
case 4: Modfily(l);break;
case 5: Insert(l);break;
case 6: Tongji(l);break;
case 7: Sort(l);break;
case 8: Save(l);break;
case 9: system("cls");Disp(l);break;
default: Wrong();getchar();break;
}
}
}