急!!!大家来帮我看一下哪错了?
#include <stdio.h>#include <string.h>
#define N 2
struct student{
long num;
char name[10];
int score;
}stu[N];
void create(char []);
void merge(char [],char [],char []);
void create_stu(char []);
void sort(char []);
int main(){
char filename[80],filename1[80],filename2[80];
printf("please input filename1:");
gets(filename1);
create_stu(filename1);
getchar();
printf("please input filename2:");
gets(filename2);
create_stu(filename2);
printf("please input new filename:");
gets(filename);
merge(filename,filename1,filename2);
sort(filename);
}
void create(char filename[]){
FILE *fp;
char ch;
if((fp=fopen(filename,"wt"))==NULL){
printf("cannot open file");
getch();
exit(1);
}
printf("input chars:");
while((ch=getchar())!='\n')
fputc(ch,fp);
fclose(fp);
getch();
}
void merge(char filename[],char filename1[],char filename2[]){
FILE *fp,*fp1,*fp2;
char ch;
if((fp=fopen(filename,"wt"))==NULL){
printf("cannot open file");
getch();
exit(1);
}
if((fp1=fopen(filename1,"rt"))==NULL){
printf("cannot open file test1.txt");
getch();
exit(1);
}
if((fp2=fopen(filename2,"rt"))==NULL){
printf("cannot open file test2.txt");
getch();
exit(1);
}
while((ch=fgetc(fp1))!=EOF)
fputc(ch,fp);
while((ch=fgetc(fp2))!=EOF)
fputc(ch,fp);
fclose(fp);
fclose(fp1);
fclose(fp2);
getch();
}
void create_stu(char filename[]){
FILE *fp;
int i;
if((fp=fopen(filename,"wt"))==NULL){
printf("cannot open file"); exit(1);
}
for(i=0;i<N;i++){
printf("\nnum:"); scanf("%ld",&stu[i].num);
printf("\nname:"); scanf("%s",stu[i].name);
printf("\nscore:"); scanf("%d",&stu[i].score);
fprintf(fp,"%ld %s %d\n",stu[i].num,stu[i].name,stu[i].score);
}
fclose(fp);
getch();
}
void sort(char filename[]){
FILE *fp;
int i,j;
struct student stu[2*N];
if((fp=fopen(filename,"rt+"))==NULL){
printf("cannot open file");
exit(1);
}
i=0;
while(!feof(fp)){
fscanf(fp,"%ld%s%d\n",&stu[i].num,stu[i].name,&stu[i].score);
i++;
}
for(i=0;i<2*N;i++){
for(j=0;j<2*N-i-1;j++){
if(stu[j].score<stu[j+1].score){
long tmp_num;
tmp_num=stu[j].num;
stu[j].num=stu[j+1].num;
stu[j+1].num=tmp_num;
char tmp_name[10];
strcpy(tmp_name,stu[j].name);
strcpy(stu[j].name,stu[j+1].name);
strcpy(stu[j+1].name,tmp_name);
int tmp_score;
tmp_score=stu[j].score;
stu[j].score=stu[j+1].score;
stu[j+1].score=tmp_score;
}
}
}
for(i=0;i<2*N;i++){
fprintf(fp,"%ld %s %d\n",stu[i].num,stu[i].name,stu[i].score);
}
fclose(fp);
}
调试的结果:
werwer.cpp: In function `void createb(char*)':
werwer.cpp:33: error: `getch' undeclared (first use this function)
werwer.cpp:33: error: (Each undeclared identifier is reported only once for
each function it appears in.)
werwer.cpp:34: error: `exit' undeclared (first use this function)
werwer.cpp: In function `void mergeb(char*, char*, char*)':
werwer.cpp:48: error: `exit' undeclared (first use this function)
werwer.cpp: In function `void create_stu(char*)':
werwer.cpp:75: error: `exit' undeclared (first use this function)
werwer.cpp: In function `void sortb(char*)':
werwer.cpp:93: error: `exit' undeclared (first use this function)
.
总是显示exit有错误,为什么啊??