求解这个c语言经典程序程序哪儿出错了

1138人阅读
------5.1 Archlinux(2)
在sublime text中使用Ctrl+b编译好C语言程序后
在使用Ctrl+Atl+b ( 自定义的快捷键 )调用命令行窗口执行编译后的文件时
出现错误D:\ (文件路径) 不是可执行文件或内部命令错误
此时的解决方案是将路径名改为英文且不能还有空格
我就是因为路径中含有文件目录中含有空格,困扰了我好几个星期,甚至一度想放弃使用这个编辑器
最后仔细分析了dos窗口的错误提示,尝试着将路径文件夹的名字更改,最后果然成功
这件事教会我了几点:
1.凡事都需要有折腾的心态,不要遇到问题搜索不到解决方案就放弃。
2.有时候问题得不到及时解决时,需要冷静下来分析,或者放下来停一段时间再来处理。问题经常是无法立马解决,可能是在很多天后,有了深刻认识之后,也有可能是碰巧就解决了。所以不要心急,心态很重要。
3.以后命名文件夹或是文件名时尽量使用英文,并且尽量少使用特殊的符号。
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:83650次
积分:2204
积分:2204
排名:第11964名
原创:143篇
评论:25条
Github地址:
文章:16篇
阅读:1667
阅读:24804
阅读:8848
(2)(7)(8)(19)(24)(1)(19)(7)(3)(2)(20)(6)(11)(4)(1)(8)(5)(2)谁帮我将这个C语言程序调出来,有一个警告两个错误,我下周星期五之前要用,老师布置的大作业:_已解决 - 阿里巴巴生意经
大家都在搜
谁帮我将这个C语言程序调出来,有一个警告两个错误,我下周星期五之前要用,老师布置的大作业:
题目:编写一个菜单驱动的仓库管理程序,货品记录存储在product.txt这个文件中。
要求如下:
1、 能输入并显示n个货品的货号、类别、名称、价格、产地、批号(按链表存储)
2、 任意输入一个类别,按该类别的价格由高到低排序
3、 任意输入一个货号,能显示该货品的货号、类别、名称、价格、产地、批号
4、 能够按货号查找某货品,可以进行增加、修改、删除操作
课程设计有单独的1.5个学分,报告模版请见存储(请务必按照格式书写),提交时间为第9周星期五中午进行当面检查.
源程序在我空间里(这里有字数限制,-_-...):/myheartgoing/blog/item/0c0d18c1029d6.html
非常感谢啊,最好写出哪里出的问题,谢啦!!!
我没多少分,但我可以给出50,真的不好意思-_-,擦... 问题补充:第一个错显示:Too many types in declaration(太多类型在声明里?);第二个错显示:Type mismatch in 'rankcategory'.(类型不匹配在rankcategory这个子程序里?)
警告是:Fuction should return a value.(子程序应该返回一个值?)
sigedanci1688的答复:
编译错误已经够改好了,没有运行确认,不知道有没有逻辑错误具体的看注释吧:#define&N&60#define&M&30#include&stdio.h&#include&stdlib.h&#include&malloc.h&#include&string.h&int&total=0,totalcategory=0,struct&goods&*head,*FILE&*struct&goods{char&no[N],category[N],name[N];float&char&origin[N];char&lot[N];struct&goods&*};//问题1.这儿需要加一个;void&main(){void&onechoice();void&twochoice();void&threechoice();void&fourchoice();int&wuchoice();//问题2.这儿的声明需要和后面的函数体一致int&sixchoice();void&interface();void&print();void&writeout();struct&goods&*creat();struct&goods&*nosearch();struct&goods&*catesearch();struct&goods&*rankcategory();struct&goods&*insert();void&modified();struct&goods&*del();//问题3.delete是C语言的关键字,所以不能用作函数名char&str,*filename,*int&onoff=1;interface();while(onoff)&&&&&&{&&&&&&&scanf(&%d&,&choices);&&&&&&&if(choices==1)&onechoice();&&&&&&&if(choices==2)&twochoice();&&&&&&&if(choices==3)&threechoice();&&&&&&&if(choices==4)&fourchoice();&&&&&&&if(choices==5)&onoff=wuchoice();&&&&&&&if(choices==6)&onoff=sixchoice();&&&&&&&clrscr();&&&&&&&interface();&&&&&&}&free(head);fclose(fp);}struct&goods&*creat(void){struct&goods&*struct&goods&*p1,*p2;p1=(struct&goods&*)malloc(sizeof(struct&goods));p2=p1;scanf(&%s&%s&%s&%l&%s&%s&,&p1-&no,&p1-&category,&p1-&name,&p1-&price,&p1-&origin,&p1-&lot);head=NULL;while(p1-&no!=&over&)&&&&&&{&&&&&&&total=total+1;&&&&&&&&&&if(total==1)&head=p1;&&&&&&&else&p2-&next=p1;&&&&&&&p2=p1;&&&&&&&p1=(struct&goods&*)malloc(sizeof(struct&goods));&&&&&&&if(p1==NULL)&&&&&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&&&printf(&Open&up&the&memory&error!Press&any&key&to&exit.&);&&&&&&&&&&&&&&&&&&&&getch();&&&&&&&&&&&&&&&&&&&&free(head);&&&&&&&&&&&&&&&&&&&&free(p1);&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&exit(0);&&&&&&&&&&&&&&&&&&&}&&&&&&&&scanf(&%s&%s&%s&%l&%s&%s&,&p1-&no,&p1-&category,&p1-&name,&p1-&price,&p1-&origin,&p1-&lot);&&&&&&}p2-&next=NULL;return(head);}void&print(struct&goods&*head){struct&goods&*p;printf(&no&&&&category&&&&name&&&&price&&&&origin&&&&lot&);p=if(head!=NULL)&&&do&&&&&{&&&&&&printf(&%s&&&&%s&&&&%s&&&&%f&&&&%s&&&&%s&,p-&no,p-&category,p-&name,p-&price,p-&origin,p-&lot);&&&&&&p=p-&&&&&&}&&&&&while(p!=NULL);}void&interface(void){printf(&================================================================================&);printf(&**&&&&&&&&&&&&&&&&&&&&&&&&&&&Warehouse&Management&&&&&&&&&&&&&&&&&&&&&&&&&&&&&**&);printf(&================================================================================&);printf(&**&&&&&&&&&&&&&1.To&input&the&datas&and&print&them&on&the&screen.&&&&&&&&&&&&&**&);printf(&================================================================================&);printf(&**&&&&&&&&&&&&&2.To&rank&the&goods&by&low&price&to&hight.&&&&&&&&&&&&&&&&&&&&&**&);printf(&================================================================================&);printf(&**&&&&&&&&&&&&&3.To&print&the&goods'&information.&&&&&&&&&&&&&&&&&&&&&&&&&&&&&**&);printf(&================================================================================&);printf(&**&&&&&&&&&&&&&4.To&search&the&goods&by&its&no&and&add,modified,or&delete&it.&**&);printf(&================================================================================&);printf(&**&&&&&&&&&&&&&6.To&Read&data&from&the&file.&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&**&);&printf(&================================================================================&);printf(&**&&&&&&&&&&&&&6.To&exit.&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&**&);&printf(&================================================================================&);printf(&Attention:Input&the&numbr&before&the&sentence&you&want&to&operate.&);}void&writeout(struct&goods&*p,&FILE&*fp1)&{&if(p!=NULL)&&&&do&&&&&{&&&&&&fwrite(p,sizeof(struct&goods),1,fp1);&&&&&&p=p-&&&&&&}&&&&&while(p!=NULL);&}struct&goods&*nosearch(struct&goods&*p,char&str[]){struct&goods&*p1;p1=p;if(p==NULL)&&&&{&&&&printf(&The&list&is&NULL!Press&any&key&to&exit&search...&);&&&&getch();&&&&clrscr();&&&&interface();&&&&return&NULL;&&&}else&while(p1)&&&&&&&&&&&{&&&&&&&&&&&&if(p1-&no==str)&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&printf(&no&&&&category&&&&name&&&&price&&&&origin&&&&lot&);&&&&&&&&&&&&&&&printf(&%s&&&&%s&&&&%s&&&&%f&&&&%s&&&&%s&,p1-&no,p1-&category,p1-&name,p1-&price,p1-&origin,p1-&lot);&&&&&&&&&&&&&&&return&(p1);&&&&&&&&&&&&&&}&&&&&&&&&&&&else&p1=p1-&&&&&&&&&&&&}printf(&Not&found.&);return&NULL;}struct&goods&*catesearch(struct&goods&*p,char&str[]){struct&goods&*p1,*p2;int&i=0;if(p==NULL)&&&&{&&&&printf(&The&list&is&NULL!Press&any&key&to&exit&search...&);&&&&getch();&&&&exit(0);&&&}else&while(p)&&&&&&&&&&&{&&&&&&&&&&&&if(p-&category==str)&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&totalcategory=totalcategory+1;&&&&&&&&&&&&&&&p1=(struct&goods&*)malloc(sizeof(struct&goods));&&&&&&&&&&&&&&&strcpy(p1-&no,p-&no);&&&&&&&&&&&&&&&strcpy(p1-&category,p-&category);&&&&&&&&&&&&&&&strcpy(p1-&name,p-&name);&&&&&&&&&&&&&&&p1-&price=p-&&&&&&&&&&&&&&&&strcpy(p1-&origin,p-&origin);&&&&&&&&&&&&&&&strcpy(p1-&lot,p-&lot);&&&&&&&&&&&&&&&if(totalcategory==1)&p2=p1;&&&&&&&&&&&&&&&else&p2-&next=p1;&&&&&&&&&&&&&&&i=1;&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&&&&&&&&&p=p-&&&&&&&&&&&&}if(i)&p1-&next=NULL;return&p2;}struct&goods&*insert(struct&goods&*head,struct&goods&*add){struct&goods&*p1,*p2,*p3;p2=p1=if(head==NULL)&&&&{&&&&head=p1;&&&&p1-&next=NULL;&&&}else&&&&&{&&&&&&while((p1-&no&p2-&no)&&&&(p2-&next!=NULL))&&&&&&&&&&&{&&&&&&&&&&&&p3=p2;&&&&&&&&&&&&p2=p2-&&&&&&&&&&&&}&&&&&&if(p1-&no&=p2-&no)&&&&&&&&{&&&&&&&&&if(head==p2)&head=p1;&&&&&&&&&else&p3-&next=p1;&&&&&&&&&p1-&next=p2;&&&&&&&&}&&&&&&else&&&&&&&&&&{&&&&&&&&&&&p2-&next=p1;&&&&&&&&&&&p1-&next=NULL;&&&&&&&&&&}&&&&&}total=total+1;return(head);}void&modified(struct&goods&*p){char&*struct&goods&*p1;printf(&Please&input&the&number&of&the&goods:&);gets(str);p1=nosearch(p,str);printf(&Please&input&the&new&data.&);printf(&no&&&&category&&&&name&&&&price&&&&origin&&&&lot&);scanf(&%s&%s&%s&%l&%s&%s&,&p1-&no,&p1-&category,&p1-&name,&p1-&price,&p1-&origin,&p1-&lot);}struct&goods&*del(struct&goods&*p)//{char&*struct&goods&*p1,*p2;printf(&Please&input&the&number&of&the&goods:&);gets(str);if(p==NULL)&&&&{&&&&printf(&The&list&is&NULL.Press&any&key&to&exit&delete...&);&&&&getch();&&&&return&NULL;&&&}p1=p;while(str!=p1-&no&&&&p1-&next!=NULL)&&&&&&{&&&&&&&p2=p1;&&&&&&&p1=p1-&&&&&&&}if(str==p1-&no)&&&{&&&&if(p1==p)&p=p1-&&&&&else&p2-&next=p1-&&&&&printf(&no&&&&category&&&&name&&&&price&&&&origin&&&&lot&);&&&&printf(&Delete:%s&&&&%s&&&&%s&&&&%f&&&&%s&&&&%s&,p1-&no,p1-&category,p1-&name,p1-&price,p1-&origin,p1-&lot);&&&&total=total-1;&&&}else&printf(&%sNot&be&foud!&,str);return(p);}void&onechoice(void){char&*filename,head=creat();gets(filename);fp=fopen(filename,&ab&);if(fp==NULL)&&&&{&&&&fp=fopen(filename,&wb&);&&&&if(fp==NULL)&&&&&&&{&&&&&&&printf(&Open&file&error!Press&any&key&to&exit...&);&&&&&&&&getch();&&&&&&&free(head);&&&&&&&exit(0);&&&&&&}&&&&&writeout(head,fp);&&&&fclose(fp);&&&}else&&&&&&&{&&&&&&&writeout(head,fp);&&&&&&&fclose(fp);&&&&&&}&&&&&&&&&printf(&Print&them(Y/N)?&);&&&str=getchar();&&&if(str=='Y'||&'y')&print(head);&&&scanf(&%d&,&choices);&&&clrscr();&&&interface();&}struct&goods&*rankcategory(struct&goods&*p)//问题4.由于在void&twochoice(void)中用到了这个函数,所以这个函数需要放到void&twochoice(void)之前{&struct&goods&*p1,*p2,*p3;&p3=p;&p-&next=p2;&p1=(struct&goods&*)malloc(sizeof(struct&goods));&if(p1==NULL)&{&&printf(&Open&up&the&memory&error!Press&any&key&to&exit.&);&&getch();&&free(head);&&free(p1);&&&exit(0);&}&&else&&while(p-&next!=NULL)&&{&&&while(p2!=NULL)&&&{&&&&if(p-&price&p2-&price)&&&&{&&&&&strcpy(p1-&no,p-&no);&&&&&strcpy(p1-&category,p-&category);&&&&&strcpy(p1-&name,p-&name);&&&&&p1-&price=p-&&&&&&strcpy(p1-&origin,p-&origin);&&&&&strcpy(p1-&lot,p-&lot);&&&&&strcpy(p2-&no,p1-&no);&&&&&strcpy(p2-&category,p1-&category);&&&&&strcpy(p2-&name,p1-&name);&&&&&p2-&price=p1-&&&&&&strcpy(p2-&origin,p1-&origin);&&&&&strcpy(p2-&lot,p1-&lot);&&&&}&&&&p2=p2-&&&&&&&}&&&p=p-&&&&p2=p-&&&}&&&&&&&&&return&p3;}void&twochoice(void){char&*strname,printf(&Please&input&the&kind&you&want&to&search:&);gets(strname);kindsearch=catesearch(head,strname);&kindsearch=rankcategory(kindsearch);printf(&Print&them(Y/N)?&);str=getchar();if(str=='Y'&||&'y')&print(kindsearch);scanf(&%d&,&choices);clrscr();interface();}void&threechoice(void){&char&*printf(&Please&input&the&number&you&want&to&search:&);gets(strname);kindsearch=nosearch(head,strname);clrscr();interface();&}void&fourchoice(void){int&onoff=1;char&*strname,struct&goods&*p;printf(&Please&input&insert,modified&or&delete:&);gets(strname);while(onoff)&&&&&&{&&&&&&&if(strname==&insert&)&&&&&&&&&&{&&&&&&&&&&p=(struct&goods&*)malloc(sizeof(struct&goods));&&&&&&&&&&kindsearch=insert(head,p);&&&&&&&&&&writeout(head,fp);&&&&&&&&&&printf(&Do&you&want&to&continue(Y/N)?&);&&&&&&&&&&str=getchar();&&&&&&&&&&if(str=='Y'||'y')&&&&&&&&&&&&{&&&&&&&&&&&&&printf(&Please&input&insert,modified&or&delete:&);&&&&&&&&&&&&&gets(strname);&&&&&&&&&&&&}&&&&&&&&&&else&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&printf(&Do&you&really&want&to&exit(Y/N)?&);&&&&&&&&&&&&&&&str=getchar();&&&&&&&&&&&&&&&if(str=='Y'||'y')&onoff=0;&&&&&&&&&&&&&&}&&&&&&&&&}&&&&&&&&else&if(strname==&modified&)&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&modified(head);&&&&&&&&&&&&&&&scanf(&%d&,&choices);&&&&&&&&&&&&&&&clrscr();&&&&&&&&&&&&&&&interface();&&&&&&&&&&&&&&&&printf(&Do&you&want&to&continue(Y/N)?&);&&&&&&&&&&&&&&&str=getchar();&&&&&&&&&&&&&&&if(str=='Y'||'y')&&&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&printf(&Please&input&insert,modified&or&delete:&);&&&&&&&&&&&&&&&&&&gets(strname);&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&else&&&&&&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&&&printf(&Do&you&really&want&to&exit(Y/N)?&);&&&&&&&&&&&&&&&&&&&&str=getchar();&&&&&&&&&&&&&&&&&&&&if(str=='Y'||'y')&onoff=0;&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&}&&&&&&&&&&&&else&if(strname==&delete&)&&&&&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&&&p=del(head);//&&&&&&&&&&&&&&&&&&&&printf(&Do&you&want&to&continue(Y/N)?&);&&&&&&&&&&&&&&&&&&&&str=getchar();&&&&&&&&&&&&&&&&&&&&if(str=='Y'||'y')&&&&&&&&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&&&&&&printf(&Please&input&insert,modified&or&delete:&);&&&&&&&&&&&&&&&&&&&&&&&gets(strname);&&&&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&&&&&else&&&&&&&&&&&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&&&&&&&&printf(&Do&you&really&want&to&exit(Y/N)?&);&&&&&&&&&&&&&&&&&&&&&&&&&str=getchar();&&&&&&&&&&&&&&&&&&&&&&&&&if(str=='Y'||'y')&onoff=0;&&&&&&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&&else&&&&&&&&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&&&&&printf(&Input&error!&);&&&&&&&&&&&&&&&&&&&&&&printf(&Reinput(Y/N)?&);&&&&&&&&&&&&&&&&&&&&&&str=getchar();&&&&&&&&&&&&&&&&&&&&&&if(str=='Y'&||&'y')&&&&&&&&&&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&&&&&&&&&printf(&Please&input&insert,modified&or&delete:&);&&&&&&&&&&&&&&&&&&&&&&&&&gets(strname);&&&&&&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&&&&&&&else&&&&&&&&&&&&&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&&&&&&&&&&printf(&Do&you&really&want&to&exit(Y/N)?&);&&&&&&&&&&&&&&&&&&&&&&&&&&&str=getchar();&&&&&&&&&&&&&&&&&&&&&&&&&&&if(str=='Y'||'y')&onoff=0;&&&&&&&&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&&&&&&&}&&&&&&&}clrscr();interface();}int&wuchoice(void)&{&FILE&*char&*struct&goods&*p1,*p2,*&printf(&Please&input&the&filename:&);gets(str);fp=fopen(str,&rb&);head=(struct&goods&*)malloc(sizeof(struct&goods));&if(fread(head,&sizeof(struct&goods),1,fp)!=1)&&&&{&&&&&free(head);&&&&&head=NULL;&&&&fclose(fp);&&&&clrscr();&&&&interface();&&&&&return(0);&&&&}&p2=while(!feof(fp))&&&&&{&&&&&&&total=total+1;&&&&&&p1=&(struct&goods&*)&malloc(sizeof(struct&goods));&&&&&&&fread(p1,&sizeof(struct&goods),1,fp);&&&&&&&if(total==1)&&&&&&&&&{&&&&&&&&&head=p1;&&&&&&&&&&p2=&&&&&&&&}&&&&&&else&&&&&&&&&&&{&&&&&&&&&&&p2-&next=p1;&&&&&&&&&&&&p2=p1;&&&&&&&&&&}&&&&&}&p2-&next=NULL;fclose(fp);&clrscr();interface();return(total);&}int&sixchoice(void){char&int&onoff=1;printf(&Do&you&really&want&to&exit(Y/N)?&);str=getchar();if(str=='Y'||'y')&&&{&&&&printf(&Press&any&key&to&exit...&);&&&&getch();&&&&onoff=0;&&&&return&&&&&&&&&}else&&&&&&{&&&&&&choices=0;&&&&&&&&&&&&while(choices&1&||&choices&6)&&&&&&&&&&&{&&&&&&&&&&&&printf(&Input&the&number&before&the&sentence&you&want&to&operate.&);&&&&&&&&&&&&scanf(&%d&,&choices);&&&&&&&&&&&&if(choices&1&||&choices&6)&printf(&Input&error!Please&reinput:&);&&&&&&&&&&&}&&&&&&&clrscr();&&&&&&interface();&&&&&&return&&&&&&}&}&
回答:共&0&条工具类服务
编辑部专用服务
作者专用服务
C语言实践中易出现的编程错误及解答
C语言程序设计实践教学是整个课程中非常重要的一个环节。它为学生提供学以致用的平台。实践环节的充分有效利用直接关系到学生程序设计能力的提高。本文根据作者多年的一线教学经验,将C语言课程实践项目里学生经常出现的共性编程错误进行汇总,并提供解答方案,以此培养学生在编程中自主查错、纠错的习惯,提高自主学习能力和编程能力。
Abstract:
C language program design practice teaching is a very important link in the whole course. It provides a platform for students?to apply what they have learned . The effective practice is directly related to improve their programming ability . According to the author’s teaching experience, the paper col ects the common programming errors and provides corresponding solutions in order to cultivate the students' habit of independent learning, to improve the ability of autonomous learning and programming ability.
作者单位:
广东白云学院电气与信息工程学院 广东广州 510450
年,卷(期):
Keywords:
机标分类号:
在线出版日期:
基金项目:
广东省高等学校教学质量与教学改革工程项目:电子信息工程专业综合改革,2013年。
本文读者也读过
相关检索词
万方数据知识服务平台--国家科技支撑计划资助项目(编号:2006BAH03B01)(C)北京万方数据股份有限公司
万方数据电子出版社C语言 已停止工作 求解哪里出错了?
&p&#include&stdio.h&&br&#include&string.h&&br&typedef struct{&br& char bookname[100];/*书名*/&br& char author[100];/*作者*/&br& char bookconcern[100];/*出版社*/&br& char ISBN[100];/*ISBN*/&br&/*出版日期*/&br&/*价格*/&br& char classification[100];/*类别*/&br& }/*书籍结构体*/&br&typedef struct{&br& char bookconcern[100];&br&&br&}book1;&/p&&p&/*子函数声明*/&br&void rank(book t[],int n);/*日期降序排列*/&br&void classify(book t[],int n);/*分类*/&/p&&p&/*主函数*/&br&main()&br&{&br& FILE *fp1;&br& FILE *fp2;&br& book t[100000];&br& memset(t,0,sizeof(book)*100000);&br& book1 t1[100000];&br& memset(t1,0,sizeof(book1)*100000);&br& int n=0;/*统计总数量*/&br&&br& if((fp1=fopen(&1.txt&,&r&))==NULL)&br& return -1;&br& if((fp2=fopen(&2.txt&,&w&))==NULL)&br& return -1;&br& while(!feof(fp1))&br& {&br&
fscanf(fp1,&%s%s%s%s%lf%lf%s&,t[n].bookname,t[n].author,t[n].bookconcern,t[n].ISBN,&t[n].time,&t[n].money,t[n].classification);&br&
n++;&br& }&br& rank(t,n);&br& classify(t,n);&br& for(i=0;i&n;i++)&br& fprintf(fp2,&%s %s %s %s %0.2lf %0.2lf %s\n&,t[i].bookname,t[i].author,t[i].bookconcern,t[i].ISBN,t[i].time,t[i].money,t[i].classification);&br& fclose(fp1);&br& fclose(fp2);&br& return 0;&br&}&br&void classify(book t[],int n)&br&{&br&
int i,j,k;&br&&br& for(i=0;i&n;i++)&br& {k=i;&br&
for(j=i+1;j&n;j++)&br&
if(strcmp(t[j].bookconcern,t[k].bookconcern)&0)&br&
if(k!=i)&br&
{s=t[k];&br&
t[k]=t[i];&br&
t[i]=s;}&br& }&br&}&br&void rank(book t[],int n)&br&{&br&
int i,j,k;&br&&br& for(i=0;i&n;i++)&br& {k=i;&br&
for(j=i+1;j&n;j++)&br&
if(t[j].time&t[k].time)&br&
if(k!=i)&br&
{s=t[k];&br&
t[k]=t[i];&br&
t[i]=s;}&br& }&br&}&/p&
#include&stdio.h&#include&string.h&typedef struct{ char bookname[100];/*书名*/ char author[100];/*作者*/ char bookconcern[100];/*出版社*/ char ISBN[100];/*ISBN*//*出版日期*//*价格*/ char classification[100];/*类别*/ }/*书籍结构体*/typedef struct{ char bookconcern[100];}book1;/*子函数声明*/void rank(book t[],int n);/*日期降序排列*/void classify(book t[],int n);/*分类*//*主函数*/main(){ FILE *fp1;…
已有帐号?
无法登录?
社交帐号登录求大神看看这个程序哪里出错了该怎么修改?求指教!_c语言吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:443,921贴子:
求大神看看这个程序哪里出错了该怎么修改?求指教!收藏
#include&stdio.h&#include&stdlib.h&#include&string.h&#include&conio.h&struct record{char id[10];char name[20];char phone[20];char adress[40];}student[20];int num=0;//外部变量num为文件中的纪录数FILE *void mainmenu();//主菜单void newrecord();//新添纪录voidsearchmenu();//查询菜单voidsearchbyid();//按编号查询voidsearchbyname();//按姓名查询voidsearchbyphone();//按电话查询voiddeletemenu();//删除菜单voiddeleteall();//删除所有voiddeleteone();//删除单个void showall();//显示所有voidreadfromfile();//读取文件void writetofile();//写入文件voiddeletebyid();//按编号删除voiddeletebyname();//按姓名删除void listbyid();//按编号排序voidlistbyname();//按姓名排序void listmenu();//排序菜单void save();//保存菜单void modify();//修改菜单void main(){readfromfile();while (1){mainmenu();}}voidreadfromfile()//从文件导入{if((fp=fopen("student.bin","rb"))==NULL){printf("\n\t\t通讯录文件不存在");if((fp=fopen("student.bin","wb"))==NULL){printf("\n\t\t建立失败");exit(0);}else{printf("\n\t\t通讯录文件已建立");printf("\n\t\t按任意键进入主菜单");getch();}exit(0);}fseek(fp,0,2); /*文件位置指针移动到文件末尾*/if(ftell(fp)&0) /*文件不为空*/{rewind(fp); /*文件位置指针移动到文件开始位置*/for(num=0;!feof(fp) && fread(&student[num],sizeof(structrecord),1,fp);num++);printf("\n\t\t文件导入成功");printf("\n\t\t按任意键返回主菜单");getch();}printf("\n\t\t文件导入成功");printf("\n\t\t通讯录文件中无任何纪录");printf("\n\t\t按任意键返回主菜单");getch();}void mainmenu()//主菜单{system("cls");printf("\n\t\t********************主菜单 ********************");printf("\n\t\t***********g-通讯信息录入 l-通讯信息查询********");printf("\n\t\t***********j-通讯信息删除 h-通讯信息显示********");printf("\n\t\t***********k-通讯信息修改 i-通讯信息保存********");printf("\n\t\t***********m-退出系统************************");printf("\n\t\t************************************************");printf("\n\t\t请选择:");choic=getch();switch (choic){case'g':newrecord();case'l':searchmenu();case'j':deletemenu();case'h':listmenu();case'k':modify();case 'i':save();case 'm':exit(0);default:mainmenu();}}voidnewrecord()//添加纪录 { printf("\n\t\t**************** 请输入学生信息 ****************\n"); printf("\n\t\t输入编号:");scanf("%s",&student[num].id); printf("\n\t\t输入姓名:");scanf("%s",&student[num].name); printf("\n\t\t输入电话号码:"); scanf("%s",&student[num].phone); printf("\n\t\t输入地址:");scanf("%s",&student[num].adress); num++; printf("\n\t\t是否继续添加?(Y/N):"); if (getch()=='y') newrecord();
} void showall()//显示所有 {
system("cls"); if(num!=0) { printf("\n\t\t*************** 以下为通讯录所有信息************"); for (i=0;i&i++) { printf("\n\t\t学号:%s",student[i].id); printf("\n\t\t姓名:%s",student[i].name); printf("\n\t\t电话:%s",student[i].phone); printf("\n\t\t地址:%s",student[i].adress); printf("\t\t"); if (i+1&num) { printf("\n\t\t__________________________"); system("pause"); } void deletemenu()//删除菜单 {
if(num==0) { printf("\n\t\t对不起,文件中无任何纪录"); printf("\n\t\t按任意键返回主菜单"); getch(); void deleteall()//删除所有 { printf("\n\t\t确认删除?(y/n)"); if (getch()=='y') { fclose(fp); if ((fp=fopen("student.bin","wb"))==NULL) { printf("\n\t\t不能打开文件,删除失败"); readfromfile(); } num=0; printf("\n\t\t纪录已删除,按任意键返回主菜单"); getch();
} void deletebyname()//按姓名删除 { int a=0; int findmark=0;
int deletemark=0;
char name[20]; printf("\n\t\t请输入要删除学生姓名:"); scanf("%s",name); for (i=a;i&i++) { if (strcmp(student[i].name,name)==NULL) { printf("\n\t\t以下是您要删除的学生纪录:"); findmark++; printf("\n\t\t________________________________"); printf("\n\t\t学号: %s",student[i].id); printf("\n\t\t姓名: %s",student[i].name); printf("\n\t\t电话: %s",student[i].phone); printf("\n\t\t________________________________"); printf("\n\t\t是否删除?(y/n)"); if (getch()=='y') { for (j=i;j&num-1;j++) /*纪录移动,从stud数组中删除之*/ student[j]=student[j+1]; num--; deletemark++; printf("\n\t\t删除成功"); if((i+1)&num) { printf("\n\t\t是否继续删除相同姓名的同学信息?(y/n)"); if (getch()=='y') { a=i;
} } printf("\n\t\t是否继续删除?(y/n)"); if (getch()=='y') deletebyname();
} if((i+1)&num) { printf("\n\t\t是否继续删除相同姓名的同学信息?(y/n)"); if (getch()=='y') { a=i;
} } } else
} if ((deletemark==0)&&(findmark==0)) { printf("\n\t\t没有该同学的纪录"); printf("\n\t\t是否继续删除?(y/n)"); if (getch()=='y') deletebyid();
} else if (findmark!=0) { printf("\n\t\t没有重名信息"); printf("\n\t\t没有该同学的纪录"); printf("\n\t\t是否继续删除?(y/n)"); if (getch()=='y') deletebyid();
} } void deletebyid()//按编号删除 { int i,j; int deletemark=0; char id[20]; printf("\n\t\t请输入要删除学生编号:"); scanf("%s",id); if(num==0) { printf("\n\t\t对不起,文件中无任何纪录"); printf("\n\t\t按任意键返回主菜单"); getch();
} for (i=0;i&i++) { if (strcmp(student[i].id,id)==NULL) { printf("\n\t\t以下是您要删除的学生纪录:"); printf("\n\t\t学号: %s",student[i].id); printf("\n\t\t姓名: %s",student[i].name); printf("\n\t\t电话: %s",student[i].phone); printf("\n\t\t是否删除?(y/n)"); if (getch()=='y') { for (j=i;j&num-1;j++) /*纪录移动,从stud数组中删除之*/ student[j]=student[j+1]; num--; deletemark++; printf("\n\t\t删除成功"); printf("\n\t\t是否继续删除?(y/n)"); if (getch()=='y') deletebyid();
} if (deletemark==0) { printf("\n\t\t没有该同学的纪录"); printf("\n\t\t是否继续删除?(y/n)"); if (getch()=='y') deletebyid();
} } void save(){FILE*fp=fopen("student.txt","w");/*写入*/for(i=0;i&n;i++){fprintf(fp,"%s%s %d %s %s %s %s %s\n",stu[i].code,stu[i].name,stu[i].age,stu[i].sex,stu[i].time,stu[i].add,stu[i].tel,stu[i].mail);}fclose(fp);}voidmodify() /*修改信息*/{
inti,item,charsex1[3],s1[LEN+1],s2[LEN+1]; /* 以姓名和学号最长长度+1为准 */printf("请输入要要修改的学生的编号:\n");scanf("%s",s1);for(i=0;i&n;i++)if(strcmp(stu[i].code,s1)==0)/*比较字符串是否相等*/num=i;printf("------------------\n");printf("1.修改姓名\n");printf("2.修改地址\n");printf("3.修改电话号码\n");printf("4.退出本菜单\n");printf("------------------\n");while(1){printf("请选择子菜单编号:");scanf("%d",&item);switch(item){case 1:printf("请输入新的姓名:\n");scanf("%s",s2);strcpy(stu[num].name,s2);case 2:printf("请输入新的地址:\n");scanf("%s",s2);strcpy(stu[num].add,s2);case 3:printf("请输入新的电话号码:\n");scanf("%s",s2);strcpy(stu[num].tel,s2);case 4:default:printf("请在1-4之间选择\n");}}} switch(choic) { case '1':showall(); case '2':searchbyid(); case '3':searchbyname(); case '4':searchbyphone(); case '5':mainmenu(); } } void showall()//显示所有 {
system("cls"); if(num!=0) { printf("\n\t\t*************** 以下为通讯录所有信息************"); for (i=0;i&i++) { printf("\n\t\t学号:%s",student[i].id); printf("\n\t\t姓名:%s",student[i].name); printf("\n\t\t电话:%s",student[i].phone); printf("\n\t\t地址:%s",student[i].adress); printf("\n\t\t邮编:%s",student[i].postcode); printf("\n\t\te-mail:%s",student[i].e_mail);printf("\t\t"); if (i+1&num) { printf("\n\t\t__________________________"); system("pause"); } } printf("\n\t\t************************************************"); } else printf("\n\t\t通讯录中无任何纪录"); printf("\n\t\t按任意键返回主菜单:"); getch();
} //按电话查询 void searchbyphone() { int mark=0;
int a=0; printf("\n\t\t****************** 按电话查找 ******************"); char phone[10]; printf("\n\t\t请输入学号:");scanf("%s",phone); for(i=0;i&i++) { if (strcmp(student[i].phone,phone)==0) { printf("\n\t\t************** 以下是您查找的学生信息 **********"); printf("\n\t\t学号:%s",student[i].id); printf("\n\t\t姓名:%s",student[i].name); printf("\n\t\t电话:%s",student[i].phone); printf("\n\t\t************************************************"); printf("\n\t\t按任意键返回主菜单:"); mark++; getch();
} } if (mark==0) { printf("\n\t\t没有改学生的信息");printf("\n\t\t按任意键返回主菜单"); getch();
} } void searchbyname()//按姓名查询 { int mark=0;
int a=0; printf("\n\t\t***************** 按姓名查找 *******************"); char name[20]; printf("\n\t\t请输入姓名:");scanf("%s",name); for(i=a;i&i++) { if (strcmp(student[i].name,name)==0) { printf("\n\t\t************* 以下是您查找的学生信息 ***********"); printf("\n\t\t学号:%s",student[i].id); printf("\n\t\t姓名:%s",student[i].name); printf("\n\t\t电话:%s",student[i].phone); printf("\n\t\t************************************************"); mark++; if ((i+1)&num) { printf("\n\t\t是否继续查找相同名字的学生信息:(y/n)"); if (getch()=='y') { a=i;
} else { printf("\n\t\t按任意键返回主菜单"); getch();
} } } if(mark!=0) { printf("\n\t\t没有相同姓名的学生纪录"); printf("\n\t\t按任意键返回主菜单"); getch();
} else { printf("\n\t\t没有相同姓名的学生纪录"); printf("\n\t\t按任意键返回主菜单"); getch();
} } void searchbyid()//按学号查询 { int mark=0;
int a=0; printf("\n\t\t****************** 按学号查找 ******************\n"); char id[10]; printf("\n\t\t请输入学号:");scanf("%s",id); for(i=0;i&i++) { if (strcmp(student[i].id,id)==0) { printf("\n\t\t************** 以下是您查找的学生信息 **********"); printf("\n\t\t学号:%s",student[i].id); printf("\n\t\t姓名:%s",student[i].name); printf("\n\t\t电话:%s",student[i].phone); printf("\n\t\t************************************************"); printf("\n\t\t按任意键返回主菜单:"); mark++; getch();
登录百度帐号推荐应用
为兴趣而生,贴吧更懂你。或}

我要回帖

更多关于 c语言经典程序 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信