M
Maxx
Recently i'm getting this strange error while trying to compile a
binary tree program.
gcc -o -Wall wordcount wordcount.c
gcc: wordcount: No such file or directory
In file included from /usr/include/stdio.h:34,
from wordcount.c:8:
/usr/lib/gcc/i686-redhat-linux/4.4.4/include/stddef.h:211: error: two
or more data types in declaration specifiers
/usr/lib/gcc/i686-redhat-linux/4.4.4/include/stddef.h:211: error: two
or more data types in declaration specifiers
wordcount.c: In function ‘talloc’:
wordcount.c:58: warning: incompatible implicit declaration of built-in
function ‘malloc’
Couldn't figure out a way to get rid of it. here is the code:
struct tnode{
char *word;
int count;
struct tnode *left;
struct tnode *right;
}
#include <stdio.h>
#include <ctype.h>
#include <string.h>
struct tnode *addtree(struct tnode *, char *);
void treeprint(struct tnode *);
struct tnode *talloc();
int main(int argc, char **argv)
{
struct tnode *root;
root=NULL;
while(--argc>0 )
{
root=addtree(root,*++argv);
}
treeprint(root);
return 0;
}
struct tnode *addtree(struct tnode *p,char *w)
{
int cond;
if(p==NULL)
{
p=talloc();
p->word=w;
p->count=1;
p->left=p->right=NULL;
}
else if((cond=strcmp(w,p->word))==0)
{
p->count++;
}
else if(cond<0)
{
p->left=addtree(p->left,w);
}
else if(cond>0)
{
p->right=addtree(p->right,w);
}
return p;
}
struct tnode *talloc(void)
{
return (struct tnode *) malloc(sizeof(struct tnode));
}
void treeprint(struct tnode *p)
{
if(p!=NULL)
{
treeprint(p->left);
printf("%s %4d\n",p->word,p->count);
treeprint(p->right);
}
}
Any help would be appreciated, this error is driving me nuts. Searched
it on google.....it returned that the error could be caused by some
bugs. But i think there's another story to it.
Thanks
Maxx
binary tree program.
gcc -o -Wall wordcount wordcount.c
gcc: wordcount: No such file or directory
In file included from /usr/include/stdio.h:34,
from wordcount.c:8:
/usr/lib/gcc/i686-redhat-linux/4.4.4/include/stddef.h:211: error: two
or more data types in declaration specifiers
/usr/lib/gcc/i686-redhat-linux/4.4.4/include/stddef.h:211: error: two
or more data types in declaration specifiers
wordcount.c: In function ‘talloc’:
wordcount.c:58: warning: incompatible implicit declaration of built-in
function ‘malloc’
Couldn't figure out a way to get rid of it. here is the code:
struct tnode{
char *word;
int count;
struct tnode *left;
struct tnode *right;
}
#include <stdio.h>
#include <ctype.h>
#include <string.h>
struct tnode *addtree(struct tnode *, char *);
void treeprint(struct tnode *);
struct tnode *talloc();
int main(int argc, char **argv)
{
struct tnode *root;
root=NULL;
while(--argc>0 )
{
root=addtree(root,*++argv);
}
treeprint(root);
return 0;
}
struct tnode *addtree(struct tnode *p,char *w)
{
int cond;
if(p==NULL)
{
p=talloc();
p->word=w;
p->count=1;
p->left=p->right=NULL;
}
else if((cond=strcmp(w,p->word))==0)
{
p->count++;
}
else if(cond<0)
{
p->left=addtree(p->left,w);
}
else if(cond>0)
{
p->right=addtree(p->right,w);
}
return p;
}
struct tnode *talloc(void)
{
return (struct tnode *) malloc(sizeof(struct tnode));
}
void treeprint(struct tnode *p)
{
if(p!=NULL)
{
treeprint(p->left);
printf("%s %4d\n",p->word,p->count);
treeprint(p->right);
}
}
Any help would be appreciated, this error is driving me nuts. Searched
it on google.....it returned that the error could be caused by some
bugs. But i think there's another story to it.
Thanks
Maxx