返回信息流c程课设,各位大牛帮忙看看哪里有错,也可以帮忙再增加几个功能。谢谢!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define M 50
typedef struct
{
char nums[10];
char clas[10];
char name[16];
char sex [10];
char room[10];
char tele[14];
}STUDENT;
int enter(STUDENT t[]);
void list(STUDENT t[],int n);
void search(STUDENT t[],int n);
int delete(STUDENT t[],int n);
int insert(STUDENT t[],int n);
void save(STUDENT t[],int n);
int load(STUDENT t[]);
void display(STUDENT t[]);
void sort(STUDENT t[],int n);
void qseek(STUDENT t[],int n);
void copy();
void print(STUDENT temp);
int find(STUDENT t[],int n,char *s) ;
int menu_select();
/******main menu*******/
main()
{
int i;
STUDENT stu[M];
int length;
clrscr();
for(;;)
{
switch(menu_select())
{
case 0:length=enter(stu);break;
case 1:list(stu,length);break;
case 2:search(stu,length);break;
case 3:length=delete(stu,length);break;
case 4:length=insert(stu,length); break;
case 5:save(stu,length);break;
case 6:length=load(stu); break;
case 7:display(stu);break;
case 8:sort(stu,length);break;
case 9:qseek(stu,length);break;
case 10:copy();break;
case 11:exit(0);
}
}
}
menu_select()
{
char s[80];
int c;
gotoxy(1,1);
printf("********************choose*********************\n");
printf(" 0. load information\n");
printf(" 1. show all information\n");
printf(" 2. search information\n");
printf(" 3. dalete information\n");
printf(" 4. insert information \n");
printf(" 5. save to file\n");
printf(" 6. exit\n");
printf("***********************************************\n");
do{
printf("\n enter the number(0~6):");
scanf("%s",s);
c=atoi(s);
}while(c<0||c>6);
return c;
}
int enter(STUDENT t[])
{
int i,n;
char *s;
clrscr();
printf("\n enter the number\n");
scanf("%d",&n);
printf("enter the information\n");
printf("number class name sex room tel\n");
printf("******************************************************\n\n");
for(i=0;i<n;i++)
{
printf("\nrenter information!!!\n");
scanf("%s%s%s%s%s%s",t.nums,t.clas,t.name,t.sex,t.room,t.tele);
printf("\n----------------------------------------------\n");
}
return n;
}
void list(STUDENT t[],int n)
{
int i;
clrscr();
printf("\n\n*******************STUDENT******************\n");
printf("number class name sex room tel\n");
printf("\n****************************************************\n");
for(i=0;i<n;i++)
printf("%-10s%-10%s-16s%-10s%-10s%-14s\n",t.nums,t.clas,t.name,t.sex,
t.room,t.tele);
if((i+1)%10==0)
{
printf("press any key to continue...\n");
getch();
}
printf("************************end*******************\n");
}
/****************search information******************/
void search(STUDENT t[],int n)
{
char s[20];
int i;
clrscr();
printf("please search num\n");
scanf("%s",s);
i=find(t,n,s);
if(i>n-1)
printf("not found\n");
else
print(t);
}
void print(STUDENT temp)
{
clrscr();
printf("\n\n********************************************\n");
printf("number class name sex room tel\n");
printf("------------------------------------------------\n");
printf("%-10s%-10s-16s%-10s%-10s%-14s\n",temp.nums,
temp.clas,temp.name,temp.sex,temp.room,temp.tele);
printf("\n**********************end***********************\n");
}
int find(STUDENT t[],int n,char *s)
{
int i;
for(i=0;i<n;i++)
{
if(strcmp(s,t.nums)==0)
return i;
}
return i;
}
int delete(STUDENT t[],int n)
{
char s[20];
int ch=0;
int i,j;
printf("please deleted num\n");
scanf("%s",s);
i=find(t,n,s);
if(i>n-1)
printf("no found not deleted\n");
else
{
print(t);
printf("Are you sure delete it(1/0)\n");
scanf("%d",&ch);
if(ch==1)
{
for(j=i+1;j<n;j++)
{
strcpy(t[j-1].nums,t[j].nums);
strcpy(t[j-1].clas,t[j].clas);
strcpy(t[j-1].name,t[j].name);
strcpy(t[j-1].sex,t[j].sex);
strcpy(t[j-1].room,t[j].room);
strcpy(t[j-1].tele,t[j].tele);
}
n--;
}
}
return n;
}
int insert(STUDENT t[],int n)
{
STUDENT temp;
int i,j;
char s[20];
printf("please input record\n");
printf("************************************************\n");
printf("num clas name sex room telephone\n");
printf("--------------------------------------------------\n");
scanf("%s%s%s%s%s%s",temp.nums,temp.clas,temp.name,temp.sex,temp.room,
temp.tele);
printf("\n------------------------------------------------\n");
printf("please input locate num \n");
scanf("%s",s);
i=find(t,n,s);
for(j=n-1;j>=i;j--)
{
strcpy(t[j+1].nums,t[j].nums);
strcpy(t[j+1].clas,t[j].clas);
strcpy(t[j+1].name,t[j].name);
strcpy(t[j+1].sex,t[j].sex);
strcpy(t[j+1].room,t[j].room);
strcpy(t[j+1].tele,t[j].tele);
}
strcpy(t.nums,temp.nums);
strcpy(t.clas,temp.clas);
strcpy(t.name,temp.name);
strcpy(t.sex,temp.sex);
strcpy(t.room,temp.room);
strcpy(t.tele,temp.tele);
n++;
return n;
}
void save(STUDENT t[],int n)
{
int i;
FILE *fp;
if((fp=fopen("record.txt","wb"))==NULL)
{
printf("can not open file\n");
exit(1);
}
printf("\nSaving file\n");
fprintf(fp,"%d",n);
fprintf(fp,"\r\n");
for(i=0;i<n;i++)
{
fprintf(fp,"%-10s%%-10s-16s%-10s%-10s%-14s",t.nums,t.clas,t.name,
t.sex, t.room,t.tele);
fprintf(fp,"\r\n");
}
fclose(fp);
printf("****save success***\n");
}
void display(STUDENT t[])
{
int id,n;
FILE *fp;
if((fp=fopen("record.txt","rb"))==NULL)
{
printf("can not open file\n");
exit(1);
}
printf("Enter order number...\n");
scanf("%d",&id);
fscanf(fp,"%d",&n);
if(id>=0&&id<n)
{
fseek(fp,(id-1)*sizeof(STUDENT),1);
print(t[id]);
printf("\r\n");
}
else
printf("no %d number record!!!\n ",id);
fclose(fp);
}
void copy()
{
char outfile[20];
int i,n;
STUDENT temp[M];
FILE *sfp,*tfp;
clrscr();
if((sfp=fopen("record.txt","rb"))==NULL)
{
printf("can not open file\n");
exit(1);
}
printf("Enter outfile name,for example c:\\f1\\te.txt:\n");
scanf("%s",outfile);
if((tfp=fopen(outfile,"wb"))==NULL)
{
printf("can not open file\n");
exit(1);
}
fscanf(sfp,"%d",&n);
fprintf(tfp,"%d",n);
fprintf(tfp,"\r\n");
for(i=0;i<n;i++)
{
fscanf(sfp,"%10s%10s%16s%10s%10s%14s\n",temp.nums,temp.clas,temp.name,
temp.sex ,temp.room,temp.tele );
fprintf(tfp,"%-10s%-10s%-16s%-10s%-10s%-14s\n",temp.nums,temp.clas,
temp.name,temp.sex ,temp.room,temp.tele);
fprintf(tfp,"\r\n");
}
fclose(sfp);
fclose(tfp);
printf("you have success in copying file!!!\n");
}
这是一条镜像帖。来源:北邮人论坛 / cpp / #32986同步于 2009/12/7
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
[求助]tc3.0关于宿舍管理的程序改错~~~
ohyes
2009/12/7镜像同步2 回复
订阅后,新回复会通过你的通知中心匿名送达。
2 条回复
关键是没排版
【 在 jokerlee 的大作中提到: 】
: LZ, 还是自己定位一下错误吧,打调或者单步一下。这么常长的程序,而且没有注释...