LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-28-2009, 01:09 PM   #1
erwfili
LQ Newbie
 
Registered: Oct 2009
Posts: 13

Rep: Reputation: 0
Smile 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!!
 
Old 10-28-2009, 01:30 PM   #2
vladmihaisima
Member
 
Registered: Oct 2002
Location: Delft, Netherlands
Distribution: Gentoo
Posts: 196

Rep: Reputation: 33
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:
 
...
and preserve formatting.
 
  


Reply

Tags
type



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
error: previous declaration of xxxxx was here horacioemilio Programming 5 07-15-2009 05:00 PM
http://www.spamhaus.org/query/bl?xxx.xxx.xxx.xxx (Server cannot send email now!) RMLinux Linux - Server 3 05-08-2009 02:06 AM
conflicting redeclaration of sys/types.h and linux/types.h schmil Programming 6 12-11-2008 02:02 PM
conflicting types for check_state nasim751 Programming 2 02-11-2008 12:58 AM
warning: conflicting types for ‘check_state’ nasim751 Programming 3 02-01-2008 01:49 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration