gpt4 book ai didi

c - 错误: exepected declaration specifiers or '...' before 'tWordInfo' in C

转载 作者:行者123 更新时间:2023-11-30 19:46:48 25 4
gpt4 key购买 nike

我有这3个C文件,一个是头文件,另一个是dictionary.c,最后一个是main.c

字典.c

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "dictionary.h"


/* Calculate the edition distance between two strings */
int getDistance(char* ref,char* word) {
char* w1=NULL;
char* w2=NULL;
int dist=0;
int i=0;
bool different=false;

/* Put the shortest word on w1 and the longest on w2. */
if(strlen(ref)<=strlen(word)) {
w1=ref;
w2=word;
} else {
w1=word;
w2=ref;
}

/* Copare char to char */
for(i=0;i<strlen(w2);i++) {

if(different) {
/* If the words are different, increase the distance */
dist++;
} else {
/* Compare the new char and word lenghts */
if(i<strlen(w1)) {
different=w1[i]!=w2[i];
} else {
/* w1 is shorter than w2 */
different=true;
}
if(different) {
/* If the words are different, increase the distance */
dist++;
}
}
}

return dist;
}

/* Get word information */
bool getWordInfo(char* str,char* word,int* languageID,int* wordID){
*languageID=-1;
*wordID=-1;
sscanf(str,"%s ; %d ; %d",word,languageID,wordID);
return *languageID>0 && *wordID>0;
}

WordList create(){
WordList l;
l.act = 1;
l.nelem = 0;
return l;
};

WordList insert(WordList l, tWordInfo e){
int i;
if (l.nelem == [250]){
printf("error");
}else{
for (i=l.nelem; l.act; i--){
l.WordInfo[i+1]= l.WordInfo[i];
}
l.WordInfo[l.act]= e;
l.nelem = l.nelem + 1;
l.act = l.act + 1;
}
return l;
}

字典.h

/* Declare the boolean type */
typedef enum {false, true} bool;



/* Calculate the edition distance between two strings */
int getDistance(char* ref,char* word);

/* Get word information */
bool getWordInfo(char* str,char* word,int* languageID,int* wordID);

char tWordInfo(int* languageID, int* wordID, char* word[128]);

typedef struct {
char tWordInfo[250];
int act;
int nelem;
}tWordList, WordList;

WordList create();

WordList insert(WordList l, tWordInfo e);

最后一个main.c

#include <stdio.h>
#include "dictionary.h"

int main(int argc, char **argv)
{
char word1[128];
char word2[128];
int langId1,wordId1;
int langId2,wordId2;
int d1,d2;
WordList l;
tWordInfo e;

create();
printf("%d\n", l.act);
printf("%s\n", l.tWordInfo[l.act]);
printf("%d\n", l.nelem);

getWordInfo("hospital ; 1 ; 1",word1,&langId1,&wordId1);
getWordInfo("hola ; 1 ; 2",word2,&langId2,&wordId2);

d1=getDistance(word1,word2);
d2=getDistance(word2,word1);

printf("[%d,%d] => %s\n",langId1,wordId1,word1);
printf("[%d,%d] => %s\n",langId2,wordId2,word2);

printf("d(%s,%s)=%d\n",word1,word2,d1);
printf("d(%s,%s)=%d\n",word2,word1,d2);

return 0;
}

程序没有结束,但我无法定义函数插入,在字典文件(.c 和 .h)中给我这个错误:在 'tWordInfo' 之前需要声明说明符或 '...' 那么什么是这里的问题以及如何解决这个问题?

另一个问题是 l.act 和 l.nelem 的 printf 没有给我 1 和 0 值,为 l.act 提供 -2,为 l.nelem 提供大量数字。为什么?

谢谢

最佳答案

TWordInfo 被声明为函数,然后在插入函数中用作参数类型。该参数需要不同的类型。

关于c - 错误: exepected declaration specifiers or '...' before 'tWordInfo' in C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23162272/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com