question about function strcmp() in C

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thungmail
    New Member
    • Mar 2008
    • 9

    question about function strcmp() in C

    There is partial code in C
    Code:
    typedef struct message {
        int messageId;
        char *messageText;
        struct message *next;
    }message;
    .....
    .....
    .....
    /* Get a node before a node */
    message *nodeBefore ( message *text ) {
        message *tem;
        tem = head;
        /* If there are only 2 nodes ( a and b ),then nodeBeforeByText of a is returning to a */
    [B]184:if ( strcmp(tem->messageText,text) == 0)[/B]
               return tem;
           else {
               while ( tem  != NULL ) {	    
    [B]188:         if ( strcmp(tem->next->messageText,text) == 0 )[/B]            
                        break;        
                 else
                        tem = tem->next;
              }
           }
           return tem;   
    }
    When I compiled there were messages :
    Code:
    q2.c:184: warning: passing arg 2 of `strcmp' from incompatible pointer type
    q2.c:188: warning: passing arg 2 of `strcmp' from incompatible pointer type
    After looking up the reference for strcmp() in library, I still dont understand why there are messages here.Can some body explain to me.
  • Laharl
    Recognized Expert Contributor
    • Sep 2007
    • 849

    #2
    text is a message*, a pointer to a message (the struct type), not a string, a char*, which is what strcmp expects.

    Comment

    • thungmail
      New Member
      • Mar 2008
      • 9

      #3
      Originally posted by Laharl
      text is a message*, a pointer to a message (the struct type), not a string, a char*, which is what strcmp expects.
      Yeah Thanks. I got it now

      Comment

      Working...