新手刚学做中文分词,不懂为什麽错,希望大家多帮忙!

凉拌菜 发布于 2013/04/29 16:55
阅读 763
收藏 0
#include<stdio.h>
#include<stdlib.h>
 #include<malloc.h>
 #include<string.h>
 


 #define OK 1;
#define ERROR 0;
#define Maxwordlength 6;
 


typedef char ElemType;
typedef int Status;


typedef struct LNode{           //创建单链表
ElemType data;
struct LNode *next; 
}LNode,*LinkList;


Status InitList_L(LinkList &L){       //初始化单链表
 L=(LinkList)malloc(sizeof(LNode));
L->next=NULL;
 return OK;
 }


Status CreateList_L(LinkList &L,ElemType a[],int n){      //后插法建立单链表
 LinkList s,r;
 int i;
 L=(LinkList)malloc(sizeof(LNode));
 r=L;
 for(i=0;i<n;i++){
s=(LinkList)malloc(sizeof(LNode));
s->data=a[i];
r->next=s;
r=s;
 }
 r->next=s;
 return OK;
 }  




int LocateElem_L(LinkList L,ElemType e){              //是否存在词,查找匹配
LinkList p=L->next;
int i=0;
while(p!=NULL&&p->data!=e){p=p->next;i++; }
if(p=NULL){ return ERROR; }
else{return(i);}
}




void read_line(char line[2000][30])   //读取词库每一行,并赋值给line[],词库读入
 {
 FILE *fp;
 char ch;
 int i;
 fp=fopen("e:\\临时存放\\汉语词组.txt","r");
 i=0;
 ch=fgetc(fp);
 while(ch!='\n'&&feof(fp))
 {
 line[i][30]=ch;
 i++;
 ch=fgetc(fp);
 }
 fclose(fp);
 }












     void main(){


char s[200];
 char line[2000][30];                          
 read_line(line[2000][30]);
 char segmentsentence(char s1[200]);


     LinkList L;                                     //用单链表建立词库
InitList_L(L);
CreateList_L(L,&line[0][30],2000);
   
printf("请输入文字:\n");                  //输入文字,调用分词函数
gets(s);
segmentsentence(&s[200]);
 


char segmentsentence(char s1[200]){                                //逆向分词法分词
char s2[200]={" "};
int len;
int n;
while(s1[0]!=0){
len=(int)strlen(s1);
if(len>Maxwordlength){ len=Maxwordlength; }
char w[200];
strncpy(w,s1+(strlen(s1)-len),len);
w[len]=0;
n=LocateElem_L(L,w);
while(len>2&&n==0)
{
len=len-1;
strncpy(w,s1+(strlen(s1)-len),len);
w[len]=0;
    n=LocateElem_L(L,w[len]);
}
strcat(w,"/");           //将分好的词用"/"隔开,并复制给s2
strcat(w,s2);
strcpy(s2,w);
}
return s2[200];


}


 }

--------------------Configuration: 1 - Win32 Debug--------------------
Compiling...
1.c
e:\临时存放\1\1.c(20) : error C2143: syntax error : missing ')' before '&'
e:\临时存放\1\1.c(20) : error C2143: syntax error : missing '{' before '&'
e:\临时存放\1\1.c(20) : error C2059: syntax error : '&'
e:\临时存放\1\1.c(20) : error C2059: syntax error : ')'
e:\临时存放\1\1.c(26) : error C2143: syntax error : missing ')' before '&'
e:\临时存放\1\1.c(26) : error C2143: syntax error : missing '{' before '&'
e:\临时存放\1\1.c(26) : error C2059: syntax error : '&'
e:\临时存放\1\1.c(26) : error C2059: syntax error : ')'
e:\临时存放\1\1.c(77) : warning C4047: 'function' : 'char (*)[30]' differs in levels of indirection from 'char '
e:\临时存放\1\1.c(77) : warning C4024: 'read_line' : different types for formal and actual parameter 1
e:\临时存放\1\1.c(78) : error C2143: syntax error : missing ';' before 'type'
e:\临时存放\1\1.c(80) : error C2275: 'LinkList' : illegal use of this type as an expression
        e:\临时存放\1\1.c(18) : see declaration of 'LinkList'
e:\临时存放\1\1.c(80) : error C2146: syntax error : missing ';' before identifier 'L'
e:\临时存放\1\1.c(80) : error C2065: 'L' : undeclared identifier
e:\临时存放\1\1.c(81) : warning C4013: 'InitList_L' undefined; assuming extern returning int
e:\临时存放\1\1.c(82) : warning C4013: 'CreateList_L' undefined; assuming extern returning int
e:\临时存放\1\1.c(86) : warning C4013: 'segmentsentence' undefined; assuming extern returning int
e:\临时存放\1\1.c(89) : error C2143: syntax error : missing ';' before 'type'
e:\临时存放\1\1.c(91) : error C2143: syntax error : missing ';' before 'type'
e:\临时存放\1\1.c(92) : error C2143: syntax error : missing ';' before 'type'
e:\临时存放\1\1.c(93) : error C2065: 's1' : undeclared identifier
e:\临时存放\1\1.c(93) : error C2109: subscript requires array or pointer type
e:\临时存放\1\1.c(94) : error C2065: 'len' : undeclared identifier
e:\临时存放\1\1.c(94) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int '
e:\临时存放\1\1.c(94) : warning C4024: 'strlen' : different types for formal and actual parameter 1
e:\临时存放\1\1.c(95) : error C2143: syntax error : missing ')' before ';'
e:\临时存放\1\1.c(95) : error C2059: syntax error : ')'
e:\临时存放\1\1.c(96) : error C2143: syntax error : missing ';' before 'type'
e:\临时存放\1\1.c(97) : error C2065: 'w' : undeclared identifier
e:\临时存放\1\1.c(97) : warning C4047: 'function' : 'char *' differs in levels of indirection from 'int '
e:\临时存放\1\1.c(97) : warning C4024: 'strncpy' : different types for formal and actual parameter 1
e:\临时存放\1\1.c(97) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int '
e:\临时存放\1\1.c(97) : warning C4024: 'strlen' : different types for formal and actual parameter 1
e:\临时存放\1\1.c(97) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'unsigned int '
e:\临时存放\1\1.c(97) : warning C4024: 'strncpy' : different types for formal and actual parameter 2
e:\临时存放\1\1.c(98) : error C2109: subscript requires array or pointer type
e:\临时存放\1\1.c(98) : error C2106: '=' : left operand must be l-value
e:\临时存放\1\1.c(99) : error C2065: 'n' : undeclared identifier
e:\临时存放\1\1.c(99) : warning C4047: 'function' : 'struct LNode *' differs in levels of indirection from 'int '
e:\临时存放\1\1.c(99) : warning C4024: 'LocateElem_L' : different types for formal and actual parameter 1
e:\临时存放\1\1.c(103) : warning C4047: 'function' : 'char *' differs in levels of indirection from 'int '
e:\临时存放\1\1.c(103) : warning C4024: 'strncpy' : different types for formal and actual parameter 1
e:\临时存放\1\1.c(103) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int '
e:\临时存放\1\1.c(103) : warning C4024: 'strlen' : different types for formal and actual parameter 1
e:\临时存放\1\1.c(103) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'unsigned int '
e:\临时存放\1\1.c(103) : warning C4024: 'strncpy' : different types for formal and actual parameter 2
e:\临时存放\1\1.c(104) : error C2109: subscript requires array or pointer type
e:\临时存放\1\1.c(104) : error C2106: '=' : left operand must be l-value
e:\临时存放\1\1.c(105) : warning C4047: 'function' : 'struct LNode *' differs in levels of indirection from 'int '
e:\临时存放\1\1.c(105) : warning C4024: 'LocateElem_L' : different types for formal and actual parameter 1
e:\临时存放\1\1.c(105) : error C2109: subscript requires array or pointer type
e:\临时存放\1\1.c(107) : warning C4047: 'function' : 'char *' differs in levels of indirection from 'int '
e:\临时存放\1\1.c(107) : warning C4024: 'strcat' : different types for formal and actual parameter 1
e:\临时存放\1\1.c(108) : warning C4047: 'function' : 'char *' differs in levels of indirection from 'int '
e:\临时存放\1\1.c(108) : warning C4024: 'strcat' : different types for formal and actual parameter 1
e:\临时存放\1\1.c(108) : error C2065: 's2' : undeclared identifier
e:\临时存放\1\1.c(108) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int '
e:\临时存放\1\1.c(108) : warning C4024: 'strcat' : different types for formal and actual parameter 2
e:\临时存放\1\1.c(109) : warning C4047: 'function' : 'char *' differs in levels of indirection from 'int '
e:\临时存放\1\1.c(109) : warning C4024: 'strcpy' : different types for formal and actual parameter 1
e:\临时存放\1\1.c(109) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int '
e:\临时存放\1\1.c(109) : warning C4024: 'strcpy' : different types for formal and actual parameter 2
e:\临时存放\1\1.c(111) : error C2109: subscript requires array or pointer type
e:\临时存放\1\1.c(111) : warning C4098: 'main' : 'void' function returning a value
e:\临时存放\1\1.c(115) : error C2059: syntax error : '}'
执行 cl.exe 时出错.


1.obj - 1 error(s), 0 warning(s)

加载中
0
王阿觉
王阿觉
你再贴长一点就i有人帮你回答了。
凉拌菜
凉拌菜
知道错了,都发了
0
Google最好搜索
凉拌菜
凉拌菜
我这里急的很,好烦啊,你能别笑了吗?你能有点建设性意见吗?
返回顶部
顶部