今晚在线讨论

babybabygo 2003-04-04 11:39:34
我在把下面函数放到一个程序里运行时出现“Too many types in declaration”,
而仅仅main()调用下面函数却能运行成功,也就是说,函数本身应该没什么问题。可是为什么会出现那情况呢?
我的QQ:93316608
int password_comp(char *s)
{
char ch,cch;
char s1[80];
int i=-1;
int j,len;
memset(s1,'\0',80);
cch='x'; len=strlen(s);
printf("\nplease enter the password:");
do { ch=getch();
if(ch!='\r')
{ printf("%c\a",cch);
i++;s1[i]=ch;}
}while(ch!='\r');
printf("\n\a\a\a\a\a\a\n");
j=strlen(s1);
if((j!=len)||(memicmp(s1,s,j)))
return(0);
else
return(1);
}
void pass(void)
{
int i,kout;
clrscr();
printf("This is library system.\n ");
for(i=0;i<3;i++)
{kout=password_comp("abcdefgh");
if(i==2) { exit(0); }
if(kout==0) printf("Password error!!!Press any key to continue...");
if (kout==1){ printf("\n Password is right!!! You are welcome!\nPress any key to continue... ");
getch();
clrscr();
break;
}
}
...全文
90 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
babybabygo 2003-04-05
  • 打赏
  • 举报
回复
不好说清,看下面吧
#include<mem.h>
#include <Fcntl.h>
#include <dos.h>
#include<string.h>
#define NULL 0
#define LEN sizeof(struct library)
#include<stdio.h>
/*自定义函数*/
int password_comp(char *s);
void pass(void);
void search(char cc);
int *open_c_file(char cch);
void output(struct library *p3);
void search();
void add();
void inputnew(void);

/*设置显示模式——80*25彩色文本*/

void textmode_set(void)
{
_AX=0x03;
__int__(0x10);
}


/*置光标位置*/
void gotoxy(int x,int y)
{
_AH=2;
_BH=0;
_DH=y-1;
_DL=x-1;
__int__(0x10);
}
/*显示光标*/

void cur_show(void)
{
_AH=1;
_CH=6;
_CL=7;
__int__(0x10);
}
/*开辟保存数据的空间*/
struct library
{ char category;
char bookname[20];
char author[10];
char information[50];
struct library*next;
}
int password_comp(char *s)
{
char ch,cch;
char s1[80];
int i=-1;
int j,len;
memset(s1,'\0',80);
cch='x'; len=strlen(s);
printf("\nplease enter the password:");
do { ch=getch();
if(ch!='\r')
{ printf("%c\a",cch);
i++;s1[i]=ch;}
}while(ch!='\r');
printf("\n\a\a\a\a\a\a\n");
j=strlen(s1);
if((j!=len)||(memicmp(s1,s,j)))
return(0);
else
return(1);
}
void pass(void)
{
int i,kout;
clrscr();
printf("This is library system.\n ");
for(i=0;i<3;i++)
{kout=password_comp("abcdefgh");
if(i==2) { exit(0); }
if(kout==0) printf("Password error!!!Press any key to continue...");
if (kout==1){ printf("\n Password is right!!! You are welcome!\nPress any key to continue... ");
getch();
clrscr();
break;
}
}

void add()
{char ch;
do{inputnew();
printf("do you want to add anther new book?(Y//N):");
gotoxy(5,8);/*x,y 待定*/
ch=getch();
}while(ch==n||ch==N);
}
void inputnew(void)
{FILE *fp;
struct library libr;
printf("input category:\n");
gotoxy(16,1);cur_show();scanf("%c",&libr.category);
printf("bookname:\n");
gotoxy(10,2);cur_show();
fflush(stdin);
gets(libr.bookname);
printf("author:\n");
gotoxy(8,3);cur_show();
gets(libr.author);
printf("Main contents of the book and where the book is placed:");
gotoxy(13,4);cur_show();
gets(libr.information);
/*将数据写入文件*/
fp=open_c_file();
if(fwrite(&libr,LEN,1,fp)!=1)
printf("error!\n");
fclose(fp);
}


void main()
{textmode_set();
pass();
handle();
}

void handle()
{ char ch;
clrscr();
printf("Search books : S \n\nAdd new books: A\n\nDellete books: D\n\n\nWhat do you want to do?");
gotoxy(28,8);ch=getch();
if(ch=="a"||ch=="A") add();
if(ch=="s"||ch=="S") search();
if(ch=="d"||ch=="D") dellete();
}
/*打开指定目录文件*/
int *open_c_file(void)
{FILE *fp;
char cch;
printf("Please input the category of the book:");
gotoxy(5,6);cur_show();/* x,y 待定*/
switch(cch)
{ case'a':case'A':if((fp=fopen("C:\\library\\A.txt","r+"))==NULL)
if((fp=fopen("C:\\library\\A.txt","r+"))==NULL)
{printf("Cannot open file\n");exit(0);}
case'b':case'B':if((fp=fopen("C:\\library\\B.txt","r+"))==NULL)
if((fp=fopen("C:\\library\\B.txt","r+"))==NULL)
{printf("Cannot open file\n");exit(0);}
case'c':case'C':if((fp=fopen("C:\\library\\C.txt","r+"))==NULL)
if((fp=fopen("C:\\library\\C.txt","r+"))==NULL)
{printf("Cannot open file\n");exit(0);}
case'd':case'D':if((fp=fopen("C:\\library\\D.txt","r+"))==NULL)
if((fp=fopen("C:\\library\\D.txt","r+"))==NULL)
{printf("Cannot open file\n");exit(0);}

case'z':case'Z':if((fp=fopen("C:\\library\\Z.txt","r+"))==NULL)
if((fp=fopen("C:\\library\\Z.txt","r+"))==NULL)
{printf("Cannot open file\n");exit(0);}

default:printf("error\n");
}
return(fp);
}

void search(void)
{FILE *fp
fp1=open_c_file();
char chr[20];
struct library *p,libr[9];
p=&libr[0];

for(i=0;i<10;i++)
{ fseek(fp,i*LEN,0);
fread(p++,LEN,1,fp); /* 把文件数据输入内存*/
}
printf("please input the bookname:");
gets(chr);
p=&libr[0];
while(p!=NULL)
{if(0==strcmp(p->bookname,str))
{output(p);break;}
else p=p->next;
}
fclose(fp);
}
void output(struct library *p3)
{
clrscr();
printf("category: %c ",p3->category);
printf("bookname:<< %s >> ",p3->bookname);
printf("author: %s\n",p3->author);
printf("Main contents and place:%s\n",p3->information);
getch();
}
void dellete(void)
{ FILE *fp;
fp=open_c_file();
}
bely_2000 2003-04-05
  • 打赏
  • 举报
回复
up
Zark 2003-04-05
  • 打赏
  • 举报
回复
请把这句话
"我在把下面函数放到一个程序里运行时出现“Too many types in declaration”,
而仅仅main()调用下面函数却能运行成功"

再解释一下.
robertnet 2003-04-05
  • 打赏
  • 举报
回复
:) 太长了,分又少!
feigehao 2003-04-05
  • 打赏
  • 举报
回复
你那个MEM。H 是什么头文件呀
YuKye 2003-04-05
  • 打赏
  • 举报
回复
!!!!
babybabygo 2003-04-05
  • 打赏
  • 举报
回复
是因为少了个;
不好意思
金笛子 2003-04-05
  • 打赏
  • 举报
回复
不是错误
是变量太多了
每个函数包括的数不要总是重复吗!
虽然不好用全局的 借用一下还是可以的吗!
试试看
zhouhu 2003-04-05
  • 打赏
  • 举报
回复
yzb1000 2003-04-05
  • 打赏
  • 举报
回复
struct library
{ char category;
char bookname[20];
char author[10];
char information[50];
struct library*next;
};
//少个分号
babybabygo 2003-04-05
  • 打赏
  • 举报
回复
要是懂的话就用不着花很多时间吧
babybabygo 2003-04-05
  • 打赏
  • 举报
回复
郁闷
babybabygo 2003-04-04
  • 打赏
  • 举报
回复
不好意思,拷上来时少个}

I AM WAITING!!

69,370

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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