errors:conflicting types and previous declaration of xxx was here
hello,
i try to compile a .c file and it always appears this error: argouments.c:8: error: conflicting types for \u2018key_t\u2019 /usr/include/sys/types.h:123: error: previous declaration of \u2018key_t\u2019 was here i cant find out where is the problem!!!!the code is #include<stdio.h> #include<stdlib.h> #include<string.h> typedef struct{ char *word; int count; }key_t; int getword(char *word,FILE *inp); int binsearch(char *word,key_t tab[],int n); int getword(char *word,FILE *inp) { return (fscanf(inp,"%s",word)); } int binsearch(char *word,key_t keytab[],int n) { int cond; int low,mid,high; low=0; high=n-1; while(low<=high) { mid=(high+low)/2; if((cond=strcmp(word,keytab[mid].word))<0) high=mid-1; else if (cond>0) low=mid+1; else return mid; } return -1; } key_t keytab[]={ "auto", 0, "break", 0, "case", 0, }; int main(int argc,char *argv[]) { int n; char word[1000]; FILE *finp; int NKEYS; if(argc!=2) { printf("error in the use of the programe"); exit(-1); } finp=fopen(argv[argc-1],"r"); if(finp==NULL) { error(); } while(getword(word,finp)!=EOF) { if(isalpha(word[0])) { if((n=binsearch(word,keytab,NKEYS))>=0) { keytab[n].count++; } } } for(n=0;n<NKEYS;n++) if(keytab[n].count>0) { printf("%4d %s\n",keytab[n].count,keytab[n].word); } fclose(finp); return 0; } please let me know if you can help me to compile this programe!! |
The name "key_t" is already used in the system headers. You should modify your code and instead of using key_t you should use something like "my_key_t".
Also, please write the code between code tags like : [ code ] ... [ /code ] (without the spaces between the parenthesis and code). It will look like: Code:
|
All times are GMT -5. The time now is 02:47 PM. |