| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1399 人关注过本帖
标题:local function definitions are illegal是说我哪错了?
只看楼主 加入收藏
voyagevio
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-10-25
收藏
 问题点数:0 回复次数:0 
local function definitions are illegal是说我哪错了?
本来都一切正常的,后来加了一句话之后再查错,就发现好多函数都出现这句提示,但是我都没有改动其他的函数啊,而且main也说有问题
error C2601: 'main' : local function definitions are illegal
fatal error C1004: unexpected end of file found
请大家帮我下了……这种时候一般是什么错了
代码:
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
#define TRUE 1
struct seqstring{/*定义字符串类型*/
    int maxnum;
    int n;
    char * c;
};
typedef struct seqstring * pseqstring;
struct node;
typedef struct node * pnode;
struct node{
    pseqstring str;
    pnode link;
};
struct linkstack{
    pnode top;
};
typedef struct linkstack * plinkstack;

pseqstring createnullstr(int m){/*创建空串*/
    pseqstring pstr=(pseqstring)malloc(sizeof(struct seqstring));
    if(pstr!=NULL){
        pstr->c=(char *)malloc(sizeof(char)*m);
        if(pstr->c){
            pstr->n=0;
            pstr->maxnum=m;
            return(pstr);
        }
        else free (pstr);
    }
    printf("out of space!\n");
    return NULL;
}

void makenext(pseqstring p,int *next){/*计算next数组*/
    int i=0,k=-1;
    next[0]=-1;
    while(i<p->n-1){
        while(k>=0&&p->c[i]!=p->c[k]) k=next[k];
        i++;
        k++;
        if(p->c[i]==p->c[k]) next[i]=next[k];
        else
            next[i]=k;
    }
}

int pmatch(pseqstring t,pseqstring p,int *next){/*模式匹配函数*/
    int i,j;
    i=0;
    j=0;
    while(i<p->n&&j<t->n)
        if(i==-1||p->c[i]==t->c[j]){
            i++;
            j++;
        }
        else
            i=next[i];
        if(i>=p->n)
            return (j-p->n+1);
        else
            return 0;
}

pseqstring getstring(void){/*读入字符串,返回相应字符串*/
    int limit,i;
    char * p;
    pseqstring res;

    printf("请输入字符串长度:\n");
    if((scanf("%d",&limit))!=1){
        printf("输入有误!\n");
        return NULL;
    }
    res=(pseqstring)malloc(sizeof(struct seqstring));/*申请空间将p扩充为字符串形式pseqstring*/
    if(res==NULL) {
        printf("failed!\n");
        return NULL;
    }
    p=(char *)malloc(sizeof(char)*limit);
    if(p==NULL){
        printf("out of space!operation failed\n");
        return NULL;
    }
    else{/*读入串存入数组中*/
        res->c=p;
        printf("输入字符串\n");
        while(getchar()!='\n') ;
        for(i=0;i<limit&&scanf("%c",&res->c[i]);i++) {
            if(res->c[i]=='\n') break;
        }
    }
    res->maxnum=limit;
    res->n=i;
    
    return res;
}

void pushlink(plinkstack plstack,pseqstring x){
    pnode p;
    p=(pnode)malloc(sizeof(struct node));
    if(p==NULL) printf("out of space\n");
    else{
        p->str=x;
        p->link=plstack->top;
        plstack->top=p;
    }
}


void output(pseqstring str){/*输出函数*/
    int i;
    if(str==NULL) printf("字符串为空");
    else {
        for(i=0;i<str->n;i++) printf("%c",str->c[i]);/*依次打印字符数组中的每个字符*/
        putchar('\n');
    }

pseqstring insert(int i,char c,pseqstring str){/*插入函数,在第i个字符后插入c,返回处理后的字符串*/
    int j;
        
    if(i<0||i>str->n){/*如果插入位置不合理,直接返回原字符串不作处理*/
        printf("原字符串只有%d个字符,操作失败\n");
        return str;
    }
    else{
        if(str->n==str->maxnum){/*如果数组已满,也不能进行插入*/
            printf("溢出!");
            return str;
        }
        else{
            for(j=str->n;j>=i;j--)
                str->c[j+1]=str->c[j];
            str->c[i]=c;
            str->n+=1;
        }
        return str;
    }
}

pseqstring del(int i,pseqstring str){/*删除下标i的元素*/
    int j;
    
    if(str->n==0){
        printf("数组空,无法删除!\n");
        return str;
    }
    for(j=i;j<str->n;j++)  str->c[j]=str->c[j+i];
    str->n-=1;
    return str;
}

int search(pseqstring str,pseqstring match){/*查找函数*/
    int * next;
    
    next=(int *)malloc(sizeof(int)*match->n);
    if(next==NULL) {
        printf("out of space\n");
        return -1;
    }
    else{
        makenext(match,next);
        return (pmatch(str,match,next));/*正常情况下返回模式匹配的结果*/
    }
}


pseqstring replace(pseqstring rep1,pseqstring rep2,pseqstring str){/*用rep2替换str中所有rep1*/
    int a,i;
    int * next1;
    
    next1=(int *)malloc(sizeof(int)*rep1->n);
    if(next1==NULL) {
        printf("out of space!\n");
        return str;
    }
    makenext(rep1,next1);
    while((a=search(str,rep1))!=0){/*当字符串中仍有可替换项时*/
        for(i=a;i<rep1->n;i++) str=del(a,str);/*依次删除rep1的字符*/
        for(i=a-1;i<rep2->n;++i) str=insert(i,rep2->c[i+1-a],str);/*依次插入rep2中的元素*/
    }
    return str;
}

pseqstring revocation(pseqstring str,plinkstack opr){
    pnode temp;
    if(opr==NULL)  {
        printf("已撤销所有操作\n");
        return str;
    }
    temp=opr->top;/*如果栈不为空,弹出栈顶元素*/
    opr->top=opr->top->link;
    free(temp);
    return (opr->top->str);
}


int main(){
    int oper,m,i;
    char c;
    pseqstring str,rep1,rep2,match;
    plinkstack opr;

    opr=(plinkstack)malloc(sizeof(struct linkstack));
    if(opr==NULL){
        printf("out of space\n");
        return -1;
    }
    opr->top=NULL;
    while(TRUE){
        printf("请选择需要执行的操作:\n");
        printf("1.输入 2.输出 3.插入 4.删除 5.查找 6.替换 7.撤消 8.结束程序\n");
        scanf("%d",&oper);
        if(oper==1){
                str=getstring();
                output(str);
                pushlink(opr,str);
        }
        if(oper==2){
                output(str);
        }
        if(oper==3){
            printf("请输入要插入的字符:\n");
            if((scanf("%c",&c))!=1) printf("输入有误,插入失败\n");                
            printf("请输入插入位置(在第几个字符后就输几):\n");
            if((scanf("%d",&i))!=1) printf("输入有误,插入失败\n");
                    
            str=insert(i,c,str);
            output(str);
            pushlink(opr,str);
        }
        if(oper==4){
                printf("请输入要删除元素的下标");
                if((scanf("%d",&i))!=1)
                    printf("输入有误,删除失败\n");
                    
                str=del(i,str);
                output(str);
                pushlink(opr,str);
        }
        if(oper==5){
                printf("请输入要匹配的字符串\n");
                match=getstring();
                if(match==NULL)  printf("failed!\n");
                else
                    printf("found!初始元素下标为%d",search(str,match));
        }
        if(oper==6){
                printf("请输入要替换部分:\n");
                rep1=getstring();
                printf("要将其替换成:\n");
                rep2=getstring();
                str=replace(rep1,rep2,str);
                output(str);
                pushlink(opr,str);
        }
        if(oper==7){
                str=revocation(str,opr);
                output(str);
        }
        if(oper==8)
                return 0;
        
    }

}

[[it] 本帖最后由 voyagevio 于 2008-10-25 20:47 编辑 [/it]]
搜索更多相关主题的帖子: function definitions illegal local 
2008-10-25 20:10
快速回复:local function definitions are illegal是说我哪错了?
数据加载中...
 
   



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

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