| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 541 人关注过本帖
标题:急!!!大家来帮我看一下哪错了?
只看楼主 加入收藏
kuailefeiyue
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2009-5-30
结帖率:100%
收藏
 问题点数:0 回复次数:2 
急!!!大家来帮我看一下哪错了?
#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有错误,为什么啊??
搜索更多相关主题的帖子: long include please create 
2009-11-23 17:52
chiZ
Rank: 2
来 自:paradise
等 级:论坛游民
帖 子:27
专家分:99
注 册:2009-10-25
收藏
得分:0 
you don't have library stdlib.h.
so add

#include<stdlib.h>
2009-11-23 18:48
positiveboy
Rank: 2
等 级:论坛游民
帖 子:17
专家分:11
注 册:2009-5-14
收藏
得分:0 
我还没见过这么长的程序.我晕!
2009-11-23 20:56
快速回复:急!!!大家来帮我看一下哪错了?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017333 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved