Thread: Error passing arg

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    26

    Error passing arg

    Hi to all,

    I have this program:

    Code:
     
    /*** HERE the various #define ***/ 
     
    #define BUFLEN 100 
     
    struct node 
    { 
           char info[BUFLEN] ; 
           struct node *pun ; 
     
    } ; 
     
     
    typedef struct node* mylist ; 
     
     
    /*** HERE the various Prototype ***/ 
     
    int main(int argc, char *argv[]) 
    { 
      int occur, n; 
      mylist testa = NULL ; 
      char myWord[20]; 
      char mystring[BUFLEN]; 
     
      /**** HERE the Input code  forf mystring and the code inserting each 
    mystring in the struct****/ 
     
        /* I search the occurrence number of myword in the entire list of mystrings*/ 
         occur = word_counter(testa, myword, n) ; 
     
         printf("The occurrences are: %d\n",occur); 
     
    } 
     
     
    int word_counter(mylist p, const char *buf, int n) 
    { 
      int j,occ; 
      char temp[BUFLEN]; 
     
     
         occ = 0; 
         n = 0; 
         j = 0;
         while (p != NULL) 
         { 
               strcpy(temp, p->info); 
              occ = eachline_counter(temp, buf, j); 
              n = n + occ; 
              printf("Occurrences for this string are: %d\n", n ) ; 
              p = p->pun ; 
         } 
         return (n) ; 
     
    } 
     
     
    int eachline_counter(char *a, char *b, int rip) 
    { 
        int cnt = 0; 
        char *sptr = a; 
     
     
        while ( *sptr != '\0' && ( sptr = strstr( sptr, b ) ) != NULL ) 
        { 
            cnt++; 
            sptr += strlen( b ); 
        } 
     
        printf( "%d\n", cnt ); 
        return (cnt); 
     
    };
    But when I compile the program, the GCC compiler return to me this
    error:
    >> In function 'word_counter'
    >> Passing arg 2 of eachline_counter discards qualifier from pointer target type

    Sure, I mistake something; but I don't see. Please can You help me ?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    buf is const in word_counter, but b is not const in eachline_counter
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer to struct
    By Paul Johnston in forum C Programming
    Replies: 4
    Last Post: 06-11-2009, 03:01 AM
  2. Replies: 10
    Last Post: 06-08-2009, 02:42 PM
  3. Replies: 5
    Last Post: 08-12-2007, 05:26 PM
  4. Ranged numbers
    By Desolation in forum Game Programming
    Replies: 8
    Last Post: 07-25-2006, 10:02 PM
  5. Compiler "Warnings"
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 04-24-2005, 01:09 PM