[ create a new paste ] login | about

Link: http://codepad.org/7c0gOGxl    [ raw code | output | fork ]

C, pasted on Jan 18:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct node{
  char *word;
  int count;
  struct node *left;
  struct node *right;
}

struct node *alloc_node(char *w){
  struct node *p;
  p=(struct node*)malloc(sizeof(struct node));
  p->word=(struct node*)malloc(sizeof(struct node));
  p->count=0;
  p->left=NULL;
  p->right=NULL;
}

main(int argc,char argv[])
{
  int i;
  int v;
  char *root;
  struct node *p;
  root=alloc_node(argv[1]);
  for(i=2;i<argc;i++)
  {
   for(p=root;;)
   {
    if((v=strcmp(argv[i],p->word==0)))
    {
    p->count++;
    break;
    }

    else if(v<0)
    {
     if(p->left=NULL)
     {
      p->left=alloc_node(argv[i]);
      break;
     }
     p=p->left;
    }

    else if(v>0)
    {
     if(p->right=NULL)
     {
      p->right=alloc_node(argv[i]);
      break;
     }
     p=p->right;
    }
   }
  }
  print_tree(root);
}

print_tree(struct node *p)
{
 if(p->left!=NULL)
 {
 print_tree(p->left);
 printf("%s %d",p->word,p->count);
 }
 if(p->right!=NULL)
 {
 print_tree(p->right);
 printf("%s %d",p->word,p->count);
 }
}


Output:
Line 12: error: two or more data types in declaration specifiers
In function 'alloc_node':
Line 15: warning: assignment from incompatible pointer type
In function 'main':
Line 27: warning: passing argument 1 of 'alloc_node' makes pointer from integer without a cast
Line 27: warning: assignment from incompatible pointer type
Line 30: warning: assignment from incompatible pointer type
Line 32: warning: passing argument 1 of 'strlen' makes pointer from integer without a cast
Line 32: warning: passing argument 1 of 'strlen' makes pointer from integer without a cast
Line 32: warning: cast to pointer from integer of different size
Line 32: warning: cast to pointer from integer of different size
Line 32: warning: cast to pointer from integer of different size
Line 32: warning: passing argument 1 of 'strlen' makes pointer from integer without a cast
Line 32: warning: cast to pointer from integer of different size
Line 32: warning: cast to pointer from integer of different size
Line 32: warning: cast to pointer from integer of different size
Line 32: warning: cast to pointer from integer of different size
Line 32: warning: cast to pointer from integer of different size
Line 32: warning: cast to pointer from integer of different size
Line 32: warning: cast to pointer from integer of different size
Line 32: warning: cast to pointer from integer of different size
Line 32: warning: passing argument 1 of 'strlen' makes pointer from integer without a cast
Line 32: warning: cast to pointer from integer of different size
Line 32: warning: cast to pointer from integer of different size
Line 32: warning: cast to pointer from integer of different size
Line 32: warning: cast to pointer from integer of different size
Line 32: warning: cast to pointer from integer of different size
Line 32: warning: cast to pointer from integer of different size
Line 32: warning: passing argument 1 of 'strcmp' makes pointer from integer without a cast
Line 32: warning: passing argument 2 of 'strcmp' makes pointer from integer without a cast
Line 42: warning: passing argument 1 of 'alloc_node' makes pointer from integer without a cast
Line 52: warning: passing argument 1 of 'alloc_node' makes pointer from integer without a cast


Create a new paste based on this one


Comments: