Thread: Don' t understand the error message

  1. #1
    Registered User
    Join Date
    Nov 2016
    Posts
    84

    Don' t understand the error message

    Hi,
    I have a question to the code below. During compiling I am getting following errors:
    ERROR CCN3068 ./6_beta.c:123 Operation between types "char*" and "int" is not allowed.
    ERROR CCN3046 ./6_beta.c:165 Syntax error.
    ERROR CCN3275 ./6_beta.c:215 Unexpected text 'int' encountered.
    ERROR CCN3275 ./6_beta.c:218 Unexpected text 'struct' encountered.
    ERROR CCN3275 ./6_beta.c:219 Unexpected text 'struct' encountered.
    CCN0793(I) Compilation failed for file ./6_beta.c. Object file not created.

    But I don' t understand it. What is the problem here? What I have to change?
    Code:
    #include <stdio.h> 
    #include <ctype.h> 
    #include <string.h> 
    #include <stdlib.h>  
      
    #define MAXWORD 100 
      
    struct tnode { 
      char *word; 
      int count; 
      struct tnode *left; 
      struct tnode *right; 
     }; 
     
     
    int getword(
     char *word, 
     int lim);
    struct tnode *talloc(
     void);
    int charcmpi(
     char a, 
     char b);
    int strcmpi(
     const char *cs, 
     const char *ct);
    struct tnode *addtree(
     struct tnode *p, 
     char *w);
    void treeprint(
     struct tnode *p);
    int tree_size(
     struct tnode *p);
    int cmp_node(
     struct tnode *a, 
     struct tnode *b);
    void insertion_sort_nodes(
     struct tnode **nodes, 
     int n);
    void collect_nodes(
     struct tnode ***collect, 
     struct tnode *node);
    
    int getword(char *word, int lim) 
    { 
      int c; 
      char *w = word; 
     
     
      while (isspace(c = getchar())) 
       ; 
      if (c != EOF) 
       *w++ = (char) c; 
     
     
      if (!isalpha(c)) { 
       *w = '\0'; 
       return c; 
      } 
      for ( ; --lim > 0; w++) 
       if ( !isalnum(*w = (char) getchar())) { 
        ungetch(*w); 
        break; 
       } 
      *w = '\0'; 
      return word[0]; 
     } 
     
     
    struct tnode *talloc(void) 
    { 
      return (struct tnode *) malloc(sizeof(struct tnode)); 
    } 
     
     
     
      
    int charcmpi(char a, char b) 
    { 
      if (a >= 'A' && a <= 'Z') 
       a += 'a' - 'A'; 
      if (b >= 'A' && b <= 'Z') 
       b += 'a' - 'A'; 
      if (a < b) 
       return -1; 
      else if (a > b) 
       return 1; 
      else 
       return 0; 
    } 
     
     
      
    int strcmpi(const char *cs, const char *ct) 
    { 
      for (; charcmpi(*cs, *ct) == 0 ; cs++, ct++) 
       if (*cs == '\0') 
        return 0; 
      return charcmpi(*cs, *ct); 
    } 
     
      
    struct tnode *addtree(struct tnode *p, char *w) 
    { 
      int cond; 
     
     
      if (p == NULL) { 
       p = talloc(); 
       p->word = strdup(w); 
       p->count = 1; 
       p->left = p->right = NULL; 
      } else if ((cond = strcmpi(w, p->word)) == 0) { 
       p->count++; 
      } else if (cond < 0) { 
       p->left = addtree(p->left, w); 
      } else { 
       p->right = addtree(p->right, w); 
      } 
      return p; 
    } 
     
     
      
    void treeprint(struct tnode *p) 
    { 
      if (p != NULL) { 
       treeprint(p->left); 
       printf("%4d %s\n", p->count, p->word); 
       treeprint(p->right); 
      } 
    } 
     
     
      
    int tree_size(struct tnode *p) 
    { 
      if (p != NULL) { 
       return 1 + tree_size(p->left) + tree_size(p->right); 
      } else { 
       return 0; 
      } 
    } 
     
     
      
    int cmp_node(struct tnode *a, struct tnode *b) 
    { 
      if (a->count == b->count) 
       return strcmpi(a->word, b->word); 
      else if (a->count > b->count) 
       return -1; // reversed 
      else 
      return 1; // reversed 
    } 
     
     
      
    void insertion_sort_nodes(struct tnode **nodes, int n) 
    { 
      int i, j; 
      struct tnode *tmp; 
     
     
      for (i = 0; i < n - 1; i++) { 
       for (j = i; j > 0; j--) { 
        if (cmp_node(*(nodes + j - 1), *(nodes + j)) > 0) { 
         tmp = *(nodes + j); 
         *(nodes + j) = *(nodes + j - 1); 
         *(nodes + j - 1) = tmp; 
        } 
       } 
      } 
    } 
     
     
      
    void collect_nodes(struct tnode ***collect, struct tnode *node) 
    { 
      if (node != NULL) { 
       **collect = node; 
       (*collect)++; 
       collect_nodes(collect, node->left); 
       collect_nodes(collect, node->right); 
      } 
    } 
     
     
    main() 
    { 
      struct tnode *root; 
      char word[MAXWORD]; 
      int i; 
     
     
      root = NULL; 
      while (getword(word, MAXWORD) != EOF) 
       if (isalpha(word[0])) 
        root = addtree(root, word); 
     
     
      int count = tree_size(root); 
     
     
      struct tnode **nodes = (struct tnode **) malloc((unsigned long) count * sizeof(struct tnode *)); 
      struct tnode **p = nodes; 
      collect_nodes(&p, root); 
      insertion_sort_nodes(nodes, count); 
     
     
      for (i = 0; i < count; i++) { 
       printf("%4d %s\n", (*(nodes + i))->count, (*(nodes + i))->word); 
      } 
     
     
      return 0; 
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    So where did you get this horrible mess of code?

    By the way your "error messages" don't correspond to the code you posted.

    You really really should decide if you're going to learn C or C++ and stick with one or the other. All you're doing by switching between languages is confusing yourself.

    Jim

  3. #3
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    1. Main always returns an integer in the C99, C11 and latest C++ standard. You should of gotten a compiler warning to this.
    2. Learn how to use comments - it would really be helpful in such a large program like this one.
    3. Your indentation could use a bit of work.
    Double Helix STL

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. trying to understand the message loop
    By bling in forum Windows Programming
    Replies: 4
    Last Post: 08-08-2008, 09:27 AM
  2. Dont understand error message
    By KIBO in forum C++ Programming
    Replies: 4
    Last Post: 04-16-2008, 09:19 AM
  3. don't understand error message
    By liven in forum C Programming
    Replies: 2
    Last Post: 02-24-2008, 09:29 PM
  4. can't understand error message.
    By nurulhafiz in forum C Programming
    Replies: 18
    Last Post: 09-13-2006, 09:25 PM
  5. error message i dont understand
    By Andystudent in forum C++ Programming
    Replies: 1
    Last Post: 05-16-2004, 10:33 AM

Tags for this Thread