| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1449 人关注过本帖
标题:local function definitions are illegal和unexpected end of file found错 ...
取消只看楼主 加入收藏
美名格的傲罗
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-12-24
结帖率:0
收藏
已结贴  问题点数:20 回复次数:5 
local function definitions are illegal和unexpected end of file found错误
众所周知,一年两度的作业季又到了,但自己做的程序错漏百出,改来改去还有几个问题,不得不求救了,求指点,万谢

代码如下:

#include<stdio.h>
#include<string.h>
#define N 10
void input(int num[N],int born[8],int salary[12],int pho[12],char name[N],char sex[N],char dep[N],char title[N]);
void sort(int num[N],int born[8],int salary[12],int pho[12],char name[N],char sex[N],char dep[N],char title[N]);
void search(int n,int num[N],int born[8],int salary[12],int pho[12],char name[N],char sex[N],char dep[N],char title[N]);
void modify(int num[N],int born[8],int salary[12],int pho[12],char name[N],char sex[N],char dep[N],char title[N]);
int main()
{   int number,c,num[N],salary[12],born[8],pho[12];
    char name[N],sex[N],dep[N],title[N];
    printf("********************************************************\n");
    printf("1.显示职工档案\n");        
    printf("2.查找职工档案\n");        
       printf("3.修改职工档案\n");
    printf("********************************************************\n");
    input(num,born,salary,pho,name,sex,dep,title);
    printf("请输入对应功能数字:");
    scanf("%d",&c);
    switch(c)
    {
       case 1:sort(num,born,salary,pho,name,sex,dep,title);break;
       case 2:printf("请输入你想修改的职工的编号:");scanf("%d",&number);search(number,num,born,salary,pho,name,sex,dep,title);break;
       case 3:modify(num,born,salary,pho,name,sex,dep,title);break;
    }
    return 0;
}

void input(int num[N],int born[8],int salary[12],int pho[12],char name[N],char sex[N],char dep[N],char title[N])
{  
    int i,j,k;
    for(j=0;j<30;j++)
    {
        printf("请输入职工编号:");
        scanf("%d",&num[i]);
        printf("该职工姓名:");
        scanf("%s",name[i]);
        printf("该职工性别:");
        scanf("%s",sex[i]);
        printf("该职工生日:");
        scanf("%d",&born[i]);
        printf("该职工所在部门:");
        scanf("%s",dep[i]);
        printf("该职工职称:");
        scanf("%s",title[i]);
        printf("该职工工资:");
        scanf("%d",&salary[i]);
        printf("联系号码:");
        scanf("%12d",&pho[i]);
        printf("输入0结束,输入1继续:");
        scanf("%d",&k);
        if(k==0)   
            break;
    }
}

void sort(int num[N],int born[8],int salary[12],int pho[12],char *name[N],char *sex[N],char *dep[N],char *title[N])
{  
    int i,j,min,temp1,temp4,temp7,temp8;
    char temp2[N],temp3[N],temp5[N],temp6[N];
    for(i=0;i<N-1;i++)
    {
        min=i;
        for(j=i;j<N;j++)
            if(num[min]>num[j])
            {
                min=j;
                temp1=num[i];
                strcpy(temp2,name[i]);
                strcpy(temp3,sex[i]);
                temp4=born[i];
                strcpy(temp5,dep[i]);
                strcpy(temp6,title[i]);
                temp7=salary[i];
                temp8=pho[i];
                num[i]=num[min];
                strcpy(name[i],name[min]);
                strcpy(sex[i],sex[min]);
                strcpy(dep[i],dep[min]);
                born[i]=born[min];
                salary[i]=salary[min];
                pho[i]=pho[min];
                strcpy(title[i],title[min]);
                num[min]=temp1;
                strcpy(name[min],temp2);
                strcpy(sex[min],temp3);
                born[min]=temp4;
                strcpy(dep[min],temp5);
                strcpy(title[min],temp6);
                salary[min]=temp7;
                pho[min]=temp8;
            }
}

void search(int n,int num[N],int born[8],int salary[12],int pho[12],char name[N],char sex[N],char dep[N],char title[N])
{   extern num[N],born[8],salary[12],pho[12];
    extern name[N], sex[N],dep[N],title[N];
    int top,bott,mid,loca,sign,i;
    top=0;
    bott=N-1;
    loca=0;
    sign=1;
    if((n<num[0])||(n>num[N-1]))
        loca=-1;
    while((sign==1)&&(top<=bott))
    {
        mid=(bott+top)/2;
        if(n==num[mid])
        {
            loca=mid;
            printf("职工编号%d,出生日期%d,工资%d,姓名%s,性别%s,所在部门%s,职称%s,联系方式%d",num[loca],born[loca],salary[loca],sex[loca],dep[loca],title[loca],pho[loca]);
            sign=-1;
        }
        else if(n<num[mid])
            bott=mid-1;
        else top=mid+1;
    }
    if(sign==1||loca==-1)
        printf("编号为%d的职工不存在!",n);
}

void modify(int num[N],int born[8],int salary[12],int pho[12],char name[N],char sex[N],char dep[N],char title[N])
{  
    int a,number,i,f;
    char c[10],d[10],e[10],g[10],h[10];
    printf("请输入你想修改的职工的编号:");
    scanf("%d",&number);
    search(number);
    a=number;
    printf("输入Y开始修改:");
    c=getchar();
    if(c=='Y'||c=='y')
    {    printf("姓名修改为:");
        gets(d);
        printf("部门修改为:");
        gets(e);
        printf("职称修改为:");
        gets(g);
        printf("工资修改为:");
        scanf("%d",&i);
        printf("性别修改为:");
        gets(h);
        printf("手机号码修改为:");
        scanf("%d",&f);
        strcpy(name[a],d);
        strcpy(dep[a],e);
        strcpy(title[a],g);
    strcpy(sex[a],h);
    salary[a]=i;
    pho[a]=f;
    }
}

错误如下:
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\设计\我的设计.cpp(95) : error C2601: 'search' : local function definitions are illegal
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\设计\我的设计.cpp(122) : error C2601: 'modify' : local function definitions are illegal
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\设计\我的设计.cpp(152) : fatal error C1004: unexpected end of file found
搜索更多相关主题的帖子: unexpected function include search local 
2013-12-24 10:59
美名格的傲罗
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-12-24
收藏
得分:0 
改来改去通过编译了,但还是停止工作啊肿么办

#include<stdio.h>
#include<string.h>
#define N 10
void sort(int num[N],int born[8],int salary[12],int pho[12],char *name,char *sex,char *dep,char *title);
void search(int n,int num[N],int born[8],int salary[12],int pho[12],char name[],char sex[],char dep[],char title[]);
void modify(int num[N],int born[8],int salary[12],int pho[12],char *name,char *sex,char *dep,char *title);
int main()
{   int number,c,num[N],salary[12],born[8],pho[12],i,k;
    char name[N],sex[N],dep[N],title[N];
    for(i=0;i<10;i++)
    {
        printf("请输入职工编号:n");
        scanf("%d",&num[i]);
        printf("该职工姓名:n");
        scanf("%s",name[i]);
        printf("该职工性别:n");
        scanf("%s",sex[i]);
        printf("该职工生日:n");
        scanf("%d",&born[i]);
        printf("该职工所在部门:n");
        scanf("%s",dep[i]);
        printf("该职工职称:n");
        scanf("%s",title[i]);
        printf("该职工工资:n");
        scanf("%d",&salary[i]);
        printf("联系号码:n");
        scanf("%12d",&pho[i]);
        printf("输入0结束输入,输入1继续输入:n");
        scanf("%d",&k);
        if(k==0)   
            break;
    }
    char *p1,*p2,*p3,*p4;  p1=name; p2=sex; p3=dep; p4=title;
    printf("********************************************************n");
    printf("1.显示职工档案n");        
    printf("2.查找职工档案n");        
       printf("3.修改职工档案n");
    printf("********************************************************n");
    printf("请输入对应功能数字:");
    scanf("%d",&c);
    switch(c)
    {
       case 1:sort(num,born,salary,pho,p1,p2,p3,p4);break;
       case 2:printf("请输入你想修改的职工的编号:");scanf("%d",&number);search(number,num,born,salary,pho,name,sex,dep,title);break;
       case 3:modify(num,born,salary,pho,p1,p2,p3,p4);break;
    }
    return 0;
}



void sort(int num[N],int born[8],int salary[12],int pho[12],char *name,char *sex,char *dep,char *title)
{  
    int i,j,min,temp1,temp4,temp7,temp8;
    char temp2[10],temp3[10],temp5[10],temp6[10];
    for(i=0;i<N-1;i++)
    {
        min=i;
        for(j=i;j<N;j++)
            if(num[min]>num[j])
            {
                min=j;
                temp1=num[i];
                strcpy(temp2,(name+i));
                strcpy(temp3,(sex+i));
                temp4=born[i];
                strcpy(temp5,(dep+i));
                strcpy(temp6,(title+i));
                temp7=salary[i];
                temp8=pho[i];
                num[i]=num[min];
                strcpy((name+i),(name+min));
                strcpy((sex+i),(sex+min));
                strcpy((dep+i),(dep+min));
                born[i]=born[min];
                salary[i]=salary[min];
                pho[i]=pho[min];
                strcpy((title+i),(title+min));
                num[min]=temp1;
                strcpy((name+min),temp2);
                strcpy((sex+min),temp3);
                born[min]=temp4;
                strcpy((dep+min),temp5);
                strcpy((title+min),temp6);
                salary[min]=temp7;
                pho[min]=temp8;
            }
    }
}




void search(int n,int num[N],int born[8],int salary[12],int pho[12],char name[],char sex[],char dep[],char title[])
{   
    int top,bott,mid,loca,sign;
    top=0;
    bott=N-1;
    loca=0;
    sign=1;
    if((n<num[0])||(n>num[N-1]))
        loca=-1;
    while((sign==1)&&(top<=bott))
    {
        mid=(bott+top)/2;
        if(n==num[mid])
        {
            loca=mid;
            printf("职工编号%d,出生日期%d,工资%d,姓名%s,性别%s,所在部门%s,职称%s,联系方式%d",num[loca],born[loca],salary[loca],sex[loca],dep[loca],title[loca],pho[loca]);
            sign=-1;
        }
        else if(n<num[mid])
            bott=mid-1;
        else top=mid+1;
    }
}


void modify(int num[N],int born[8],int salary[12],int pho[12],char name[],char sex[],char dep[],char title[])
{  
    int a,number,i,f;
    char c,d[10],e[10],g[10],h[10];
    printf("请输入你想修改的职工的编号:");
    scanf("%d",&number);
    search(number,num,born,salary,pho,name,sex,dep,title);
    a=number;
    printf("输入Y开始修改:");
    c=getchar();
    if(c=='Y'||c=='y')
    {    printf("姓名修改为:");
        gets(d);
        printf("部门修改为:");
        gets(e);
        printf("职称修改为:");
        gets(g);
        printf("工资修改为:");
        scanf("%d",&i);
        printf("性别修改为:");
        gets(h);
        printf("手机号码修改为:");
        scanf("%d",&f);
        strcpy((name+a),d);
        strcpy((dep+a),e);
        strcpy((title+a),g);
        strcpy((sex+a),h);
        salary[a]=i;
        pho[a]=f;
    }
}
2013-12-24 16:41
美名格的傲罗
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-12-24
收藏
得分:0 
回复 3楼 embed_xuel
学是最近学了,但是之前就写好了,改掉好麻烦的说
2013-12-24 16:52
美名格的傲罗
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-12-24
收藏
得分:0 
回复 5楼 embed_xuel
...书上就学了这么多,我也想写的高级点啊,而且又写不对,除非去网上抄,我们寝室其他三个人都认命,打算挂科了。
2013-12-24 17:00
美名格的傲罗
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-12-24
收藏
得分:0 
回复 7楼 so_love
换成结构体了,,出来的错误怎么解决啊


#include<stdio.h>
#define N 10
void sort(struct Student studen[]);
void search(int n,struct Student studen[]);
void modify(struct Student studen[]);

struct Student
{   
    int num[N];char name[N];int born[8];int salary[12];int pho[12];char sex[N];char dep[N];char title[N];
};

int main()
{   
    struct Student studen[N],*p=studen;
    int number,c,i,k;
    printf("请输入职工编号、姓名、生日、工资、联系号码、性别、部门和职称,以逗号隔开:\n");
    for(i=0;i<10;i++)
    {  scanf("%d,%s,%d,%d,%12d,%s,%s,%s",&studen[i].num,studen[i].name,&studen[i].born,&studen[i].salary,&studen[i].pho,studen[i].sex,studen[i].dep,studen[i].title);
        printf("输入0结束,输入1继续:\n");
        scanf("%d",&k);
        if(k==0)   
            break;
    {
    printf("********************************************************\n");
    printf("1.显示职工档案\n");        
    printf("2.查找职工档案\n");        
       printf("3.修改职工档案\n");
    printf("********************************************************\n");
    printf("请输入对应功能数字:");
    scanf("%d",&c);
    switch(c)
    {
       case 1:sort(p);break;
       case 2:printf("请输入你想修改的职工的编号:");scanf("%d",&number);search(number,p);break;
       case 3:modify(p);break;
    }
    return 0;
}



void sort(struct Student studen[])
{  int i,j;
   stuct Student temp;
    for(i=0;i<N-1;i++)
    {
        min=i;
        for(j=i;j<N;j++)
            if(studen[min].num>studen[j].num)
            {
                temp=studen[min];
                studen[min]=studen[i];
                studen[i]=temp;
            }
    }
}




void search(int n,struct Student studen[])
{   
    int top,bott,mid,loca,sign;
    top=0;
    bott=N-1;
    loca=0;
    sign=1;
    if((n<studen[0].num)||(n>studen[N-1].num))
        loca=-1;
    while((sign==1)&&(top<=bott))
    {
        mid=(bott+top)/2;
        if(n==studen[mid].num)
        {
            loca=mid;
            printf("职工编号%d,出生日期%d,工资%d,姓名%s,性别%s,所在部门%s,职称%s,联系方式%d",studen[loca].num,studen[loca].born,
                studen[loca].salary,studen[loca].sex,studen[loca].dep,studen[loca].title,studen[loca].pho);
            sign=-1;
        }
        else if(n<studen[mid].num)
            bott=mid-1;
        else top=mid+1;
    }
}


void modify(struct Student studen[])
{  
    int number,i;
    char c;
    sruct Student mostu,a;
    printf("请输入你想修改的职工的编号:");
    scanf("%d",&number);
    search(number,struct Student studen[]);
    printf("输入Y开始修改:");
    c=getchar();
    if(c=='Y'||c=='y')
    {   
        for(i=0;i<11;i++);
             scanf("%d,%s,%d,%d,%12d,%s,%s,%s",&mostu.num,mostu.name,&mostu.born,&mostu.salary,&mostu.pho,mostu.sex,mostu.dep,mostu.title);
        a=mostu;
        mostu=studen;
        studen=mostu;
    }
}


错误:
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\11\11.cpp(43) : error C2601: 'sort' : local function definitions are illegal
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\11\11.cpp(62) : error C2601: 'search' : local function definitions are illegal
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\11\11.cpp(88) : error C2601: 'modify' : local function definitions are illegal
C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\11\11.cpp(108) : fatal error C1004: unexpected end of file found

 
2013-12-24 18:40
美名格的傲罗
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-12-24
收藏
得分:0 
回复 7楼 so_love
连击了
 

[ 本帖最后由 美名格的傲罗 于 2013-12-24 19:38 编辑 ]
2013-12-24 18:43
快速回复:local function definitions are illegal和unexpected end of file fo ...
数据加载中...
 
   



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

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