求大神帮助!!急!

angel20121205 2017-05-05 07:52:19
图书馆管理系统
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>


typedef struct
{
char ISBN[10];
char book[30];
char author[20];
int edition;
char press[50];
int year;
}Bookinfo;

static int n=0;

int menu_select()
{
char c;
do {
system("cls");
printf("0316\n");
printf("贾");
printf("1.Input records\n");
printf("2.Display All Records\n");
printf("3.Delete a Record\n");
printf("4.Sort\n");
printf("5.Insert a Record\n");
printf("6.Query\n");
printf("7.Add Records from a Text File\n\n\n");
printf("8.Write to a Text File\n");
printf("0.Quit\n");
printf("Give your choice:");
c=getchar();
}while(c<'0'||c>'8');
return(c-'0');
}

int Input(Bookinfo dictList[],int n)
{
int i;
printf("请输入书号:");
scanf("%s",dictList[n].ISBN);
printf("\n请输入书名:");
scanf("%s",dictList[n].book);
printf("\n请输入作者:");
scanf("%s",dictList[n].author);
printf("\n请输入版本号:");
scanf("%d",&dictList[n].edition);
printf("\n请输入出版社名:");
scanf("%s",dictList[n].press);
printf("\n请输入出版年:");
scanf("%d",&dictList[n].year);
printf("\n添加成功");
n+=1;
printf("\n确认是否输入下一条记录(是请按1)");
scanf("%d",&i);
if(i==1) n=Input(dictList,n);
else return(n);
}

void Display(Bookinfo dictList[],int n)
{
int i;
for(i=1;i<n;i++)
{
printf("-10s",dictList[i].ISBN);
printf("-30s",dictList[i].book);
printf("-20s",dictList[i].author);
printf("-20d",dictList[i].edition);
printf("-50s",dictList[i].press);
printf("-4d",dictList[i].year);
printf("\n");
if(i%10==0)
{
system("pause");
system("cls");
}
}
}
int Delete(Bookinfo dictList[],int n,char *book)
{
int i;
for(i=0;i<n;i++)
{
if(strcmp(book,dictList[i].book)==0)
{
printf("-10s",dictList[i].ISBN);
printf("-30s",dictList[i].book);
printf("-20s",dictList[i].author);
printf("-20d",dictList[i].edition);
printf("-50s",dictList[i].press);
printf("-4d",dictList[i].year);
printf("\n");
}
printf("请输入待删除书的书号");

for(;i<n;i++)
dictList[i]=dictList[i+1];
n-=1;
return(n);
}
}
int Delete_a_record(Bookinfo dictList[],int n)
{
char name[30];
char *book=name;
int i;
printf("请输入待删除的书名:");
scanf("%s",name);
printf("是否删除?(确定请按1)");
if(i==1)
n=Delete(dictList,n,name);
return(n);
}

void Sort_by_name(Bookinfo dictList[],int n)
{
int i,j,k;
Bookinfo t;
for(i=0;i<n-1;i++)
{
k=i;
for(j=i+1;j<n;j++)
if(strcmp(dictList[k].book,dictList[j].book)>0) k=j;
if(k!=i)
{ t=dictList[i]; dictList[i]=dictList[k]; dictList[k]=t; }
}
}

int Insert(Bookinfo dictList[],int n,Bookinfo *s)
{
int i;
for(i=0;i<n;i++)
if(strcmp(dictList[i].book,(*s).book)>0)
dictList[i]=(*s);
Sort_by_name(dictList,n+1);
return(n+1);
}

int Insert_a_record(Bookinfo dictList[],int n)
{
Bookinfo s;
Bookinfo *p;
p=&s;
printf("请输入书号:");
scanf("%s",s.ISBN);
printf("\n请输入书名:");
scanf("%s",s.book);
printf("\n请输入作者:");
scanf("%s",s.author);
printf("\n请输入版本号:");
scanf("%d",&s.edition);
printf("\n请输入出版社名:");
scanf("%s",s.press);
printf("\n请输入出版年:");
scanf("%d",&s.year);
n++;
n=Insert(dictList,n,p);
return(n);
}

int Query(Bookinfo dictList[],int n,char *book)
{
int i,j=0;
for(i=0;i<n;i++)
if(strcmp(book,dictList[i].book)==0)
{
printf("%-10s",dictList[i].ISBN);
printf("%-30s",dictList[i].book);
printf("%-20s",dictList[i].author);
printf("%-20d",dictList[i].edition);
printf("%-50s",dictList[i].press);
printf("%-4d\n",dictList[i].year);
printf("\n");
j++;
}
if(j!=0)
return(j);
else
return(-1);
}


void Query_a_record(Bookinfo dictList[],int n)
{
char name[30];
char *book=name;
int i;
printf("请输入待查找的书名:");
scanf("%s",name);
i=Query(dictList,n,book);
if(i==-1)
printf("查找失败\n");
else
printf("查找成功\n");
}

int AddfromText(Bookinfo dictList[],int n,char *filename)
{
int i,t;
FILE *fp;
fp=fopen(filename,"r");
typedef struct a[500];
typedef struct *q;
if(fp==NULL)
{
printf("该文件不存在!\n");
exit(1);
}
for(i=0;feof(fp)==0;i++)
{
fscanf(fp,"%s",dictList[i].ISBN);
fscanf(fp,"%s",dictList[i].book);
fscanf(fp,"%s",dictList[i].author);
fscanf(fp,"%d",&dictList[i].edition);
fscanf(fp,"%s",dictList[i].press);
fscanf(fp,"%d",&dictList[i].year);
n=Insert(dictList,n,&dictList);
}
printf("成功插入数据\n");
fclose(fp);
return(n);
}




void WritetoText(Bookinfo dictList[],int n,char *filename)
{
int i;
FILE *fp1;
fp1=fopen(filename,"w");
if(fp1==NULL)
{
printf("文件打开失败:");
exit(1);
}
for(i=0;i<n;i++)
{
fprintf(fp1,"%-10s%-30s%-20s%-20d%-50%s-4%d\n",dictList[i].ISBN,dictList[i].book,dictList[i].author,dictList[i].edition,dictList[i].press,dictList[i].year);
printf("记录已写入文件");
}
fclose(fp1);
}



void main()
{
Bookinfo books[500];
static int m=0;
for(; ;)
{
switch(menu_select())
{
case 1:
printf("Input records\n");
m=Input(books,m);
printf("现在共有%d本书\n",m);
system("pause");
break;
case 2:
printf("Display All Records\n");
Display(books,m);
system("pause");
break;
case 3:
printf("Delete a Record\n");
m=Delete_a_record(books,m);

system("pause");
break;
case 4:
printf("Sort\n");
Sort_by_name(books,m);
system("pause");
break;
case 5:
printf("Insert a Record\n");
m=Insert_a_record(books,m);
printf("现在共有%d本书\n",m);
system("pause");
break;
case 6:
printf("Query\n");
Query_a_record(books,m);
system("pause");
break;
case 7:
printf("Add Records from a Text File\n\n\n");
m=AddfromText(books,m,"Dictory.txt");
system("pause");
break;
case 8:
printf("Write to a Text File\n");
WritetoText(books,m,"Records.txt");
system("pause");
break;
case 0:
printf("Quit\n");
system("pause");
exit(0);
}
}
}


--------------------Configuration: ex0101 - Win32 Debug--------------------
Compiling...
ex0101.c
C:\Users\84608\Desktop\C语言课程设计\ex0101.c(206) : error C2143: syntax error : missing ';' before 'type'
C:\Users\84608\Desktop\C语言课程设计\ex0101.c(207) : error C2143: syntax error : missing ';' before 'type'
C:\Users\84608\Desktop\C语言课程设计\ex0101.c(221) : warning C4047: 'function' : 'struct Bookinfo *' differs in levels of indirection from 'struct Bookinfo ** '
C:\Users\84608\Desktop\C语言课程设计\ex0101.c(221) : warning C4024: 'Insert' : different types for formal and actual parameter 3
Error executing cl.exe.

ex0101.exe - 2 error(s), 2 warning(s)
...全文
263 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2017-05-09
  • 打赏
  • 举报
回复
printf里面的%和变量的一一对应关系 scanf里面的%和变量以及变量前加不加&的一一对应关系 是C代码中非常容易出错的地方,而且通常编译还不出错。 所以在编译源代码之前值得专门仔细检查一遍甚至多遍。
自信男孩 2017-05-08
  • 打赏
  • 举报
回复
引用 2 楼 angel20121205 的回复:
想定义一个数组,它的元素为这个结构体类型数据 请问应该怎么做?
结构体类型的数组和普通类型的数组定义方法一样,类型加数组名。
赵4老师 2017-05-08
  • 打赏
  • 举报
回复
偶遇到类似问题都是用 “每次用/*...*/注释掉不同部分再重新编译,直到定位到具体语法出错的位置。” 的方法解决的。
自信男孩 2017-05-08
  • 打赏
  • 举报
回复
void Display(Bookinfo dictList[],int n)
{
    int i;
    for(i=1;i<n;i++)
    {
        printf("%-10s",dictList[i].ISBN);
        printf("%-30s",dictList[i].book);
        printf("%-20s",dictList[i].author);
        printf("%-20d",dictList[i].edition);
        printf("%-50s",dictList[i].press);
        printf("%-4d",dictList[i].year);
        printf("\n");
        if(i%10==0)
        {
            system("pause");
            system("cls");
        }
    }
}
printf缺少%
  • 打赏
  • 举报
回复
引用 2 楼 angel20121205 的回复:
想定义一个数组,它的元素为这个结构体类型数据 请问应该怎么做?
那关键是要看你的结构体类型是什么了。我给你举个例子好了。

//定义一个结构体
struct Stu {
int ID;
char name[4];
}
//起个别名然后方便定义
typedef struct Stu Student;
//定义数组
Student s[4];
//不起别名重新定义
struct Stu s[4];
gaozeng851998821 2017-05-06
  • 打赏
  • 举报
回复
typedef struct a[500]; typedef struct *q; 这两行程序的目的是什么?没有看到你在函数中使用,你想使用的结构体类型是哪种? 如果是Bookinfo 类型,那就 Bookinfo a[500] ; Bookinfo * q;
angel20121205 2017-05-05
  • 打赏
  • 举报
回复
想定义一个数组,它的元素为这个结构体类型数据 请问应该怎么做?
  • 打赏
  • 举报
回复
说实话,这种语法错误很常见,原因很多,不列举了,但一般都不会是真的缺少分号的问题,但一般都是在这个语句的附近,检查一遍就好了。 然后说你的问题,
typedef struct a[500];
typedef struct *q;
你这两个代码是要干什么?声明struct关键字的别名?
//你可以这样声明某一种已定义结构体的别名
typedef struct {
//....
}Student;
//或是这样
struct Student {
//...
}
typedef struct Student Stu;
在某网站上看到的某大神的经验之谈,特此分享给各位,你还在等什么,抓起青春的尾巴,向着自己目标迈进吧 一段 你刚开始进入这行,对PMOS/NMOS/BJT什么的只不过有个大概的了解,各种器件的特性你也不太清楚,具体设计成什么样的电路你也没什么主意,你的电路图主要看国内杂志上的文章,或者按照教科书上现成的电路,你总觉得他们说得都有道理。你做的电路主要是小规模的模块,做点差分运放,或者带隙基准的仿真什么的你就计算着发文章,生怕到时候论文凑不够。总的来说,基本上看见运放还是发怵。你觉得spice是一个非常难以使用而且古怪的东西。 二段 你开始知道什么叫电路设计,天天捧着本教科书在草稿纸上狂算一气。你也经常开始提起一些技术参数,Vdsat、lamda、early voltage、GWB、ft之类的。总觉得有时候电路和手算得差不多,有时候又觉得差别挺大。你也开始关心电压,温度和工艺的变化。例如低电压、低功耗系统什么的。或者是超高速高精度的什么东东,时不时也来上两句。你设计电路时开始计划着要去tape out,虽然tape out看起来还是挺遥远的。这个阶段中,你觉得spice很强大,但经常会因为AC仿真结果不对而大伤脑筋。 三段 你已经和PVT斗争了一段时间了,但总的来说基本上还是没有几次成功的设计经验。你觉得要设计出真正能用的电路真的很难,你着想建立自己的信心,可你不知道该怎么办。你开始阅读一些JSSC或者博士论文什么的,可你觉得他们说的是一回事,真正的芯片或者又不是那么回事。你觉得Vdsat什么的指标实在不够精确,仿真器的缺省设置也不够满足你的要,于是你试着仿真器调整参数,或者试着换一换仿真器,但是可它们给出的结果仍然是有时准有时不准。你上论坛,希望得到高手的指导。可他们也是语焉不详,说得东西有时对有时不对。这个阶段中,你觉得spice虽然很好,但是帮助手册写的太不清楚了。 四段 你有过比较重大的流片失败经历了。你知道要做好一个电路,需要精益精,需要战战兢兢的仔细检查每一个细节。你发现在设计过程中有很多不曾设想过的问题,想要做好电路需要完整的把握每一个方面。于是你开始系统地重新学习在大学毕业时已经卖掉的课本。你把能能找到的相关资料都仔细的看了一遍,希望能从中找到一些更有启发性的想法。你已经清楚地知道了你需要达到的电路指标和性能,你也知道了电路设计本质上是需要做很多合理的折中。可你搞不清这个“合理” 是怎么确定的,不同指标之间的折中如何选择才好。你觉得要设计出一个适当的能够正常工作的电路真的太难了,你不相信在这个世界上有人可以做到他们宣称的那么好,因为聪明如你都觉得面对如此纷杂的选择束手无策,他们怎么可能做得到?这个阶段中,你觉得spice功能还是太有限了,而且经常对着"time step too small"的出错信息发呆,偶尔情况下你还会创造出巨大的仿真文件让所有人和电脑崩溃。 五段 你觉得很多竞争对手的东西不过如此而已。你开始有一套比较熟悉的设计方法。但是你不知道如何更加优化你手头的工具。你已经使用过一些别人编好的脚本语言,但经常碰到很多问题的时候不能想起来用awk或者perl搞定。你开始大量的占用服务器的仿真时间,你相信经过大量的仿真,你可以清楚地把你设计的模块调整到合适的样子。有时候你觉得做电路设计简直是太无聊了,实在不行的话,你在考虑是不是该放弃了。这个阶段中,你觉得spice好是好,但是比起 fast spice系列的仿真器来,还是差远了;你开始不相信AC仿真,取而代之的是大量的transient仿真。 六段 你开始明白在这个世界中只有最合适的设计,没有最好的设计。你开始有一套真正属于自己的设计方法,你会倾向于某一种或两种仿真工具,并能够熟练的使用他们评价你的设计。你开始在设计中考虑PVT的变化,你知道一个电路从开始到现在的演化过程,并能够针对不同的应用对他们进行裁减。你开始关注功耗和面积,你tape out的芯片开始有一些能够满足产品要了。但是有时候你还是不能完全理解一些复杂系统的设计方法,并且犯下一些愚蠢的错误并导致灾难性后果。你开始阅读 JSSC时不只是挑一两片文章看看,或许把JSSC作为厕所读物对你来说是一个不错的选择。在这个阶段中,你觉得spice是一个很伟大的工具,你知道如何在spice中对精度和速度做合理的仿真,并随时做出最合适的选择。 七段 你开始真正理解模拟电路设计的本质,无论对于高精度系统还是高速度系统都有自己独有的看法和经验。你可以在系统级对不同的模块指标进行折中以换取最好的性能。你会了解一个潜在的市场并开始自己的产品定义,并且你知道只要方法正确,你设计出的产品会具有很好的竞争力。你可以从容的从头到脚进行整个电路的功能和指标划分,你了解里面的每一个技术细节和他们的折中会对于你的产

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧