need help on linked list

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tirivamwe
    New Member
    • Oct 2006
    • 8

    #1

    need help on linked list

    the function first search a word from the linked list. if found it then increment the numWords (number of words in listfor that word) and if not found it shoud create a new node for the word.

    the code is:

    Code:
    void AddWords( char text[30])
    {
     
     check=head;
     
    while (check!=NULL)
          {
           if (strcmp(check->words,text[30])==0)
              {
                check->numWords++;
                break;
              }
           else
               {                                
                 newNode=getmem();
                 strncpy(newNode->words,text, 29);
                 newNode->next=head;
                 head=newNode;                                
               }
          check=check->next;     
    
    }

    i am having this compiler error:

    Warning] passing arg 2 of `strcmp' makes pointer from integer without a cast

    for this line of code:

    Code:
    if (strcmp(check->words,text[30])==0)
  • yogesh_anand
    New Member
    • Apr 2006
    • 26

    #2
    Originally posted by tirivamwe
    the function first search a word from the linked list. if found it then increment the numWords (number of words in listfor that word) and if not found it shoud create a new node for the word.

    the code is:

    Code:
    void AddWords( char text[30])
    {
     
     check=head;
     
    while (check!=NULL)
          {
           if (strcmp(check->words,text[30])==0)
              {
                check->numWords++;
                break;
              }
           else
               {                                
                 newNode=getmem();
                 strncpy(newNode->words,text, 29);
                 newNode->next=head;
                 head=newNode;                                
               }
          check=check->next;     
    
    }

    i am having this compiler error:

    Warning] passing arg 2 of `strcmp' makes pointer from integer without a cast

    for this line of code:

    Code:
    if (strcmp(check->words,text[30])==0)

    Try this:
    if (strcmp(check->words,text)==0 )
    Two arguments to strcmp shd. be adresses always..
    Array name is equal to its address so pass text only..

    Comment

    • arne
      Recognized Expert Contributor
      • Oct 2006
      • 315

      #3
      Originally posted by tirivamwe

      Warning] passing arg 2 of `strcmp' makes pointer from integer without a cast

      for this line of code:

      Code:
      if (strcmp(check->words,text[30])==0)
      It's a warning, not an error. The compiler warns you that strcmp expected another type for its 2nd argument, namely 'const char *', but you passed an int. So the compiler will translate it, but it may not what you wanted ...

      BTW, why did you start a new thread? Didn't we discuss this yesterday? What was wrong with thread http://www.thescripts. com/forum/thread552877.ht ml ??

      Comment

      • tirivamwe
        New Member
        • Oct 2006
        • 8

        #4
        i tried that but when debugging i am having this error

        An Access violation(segme nt fault) raised in your program.

        the line of code crushinhg the program is:


        Code:
        if (strcmp(check->words,temp)==0)

        Comment

        • arne
          Recognized Expert Contributor
          • Oct 2006
          • 315

          #5
          Originally posted by tirivamwe
          i tried that but when debugging i am having this error

          An Access violation(segme nt fault) raised in your program.

          the line of code crushinhg the program is:


          Code:
          if (strcmp(check->words,temp)==0)
          In my program? IIRC, I haven't sent you any program :)

          Comment

          • arne
            Recognized Expert Contributor
            • Oct 2006
            • 315

            #6
            Originally posted by arne
            In my program? IIRC, I haven't sent you any program :)
            Oops, these were the compiler's word spoken to you, not your words spoken to me ... got it.

            Comment

            • tirivamwe
              New Member
              • Oct 2006
              • 8

              #7
              Originally posted by arne
              Oops, these were the compiler's word spoken to you, not your words spoken to me ... got it.
              in just dont get it . what are u trying to say

              Comment

              • tirivamwe
                New Member
                • Oct 2006
                • 8

                #8
                Originally posted by yogesh_anand
                Try this:
                if (strcmp(check->words,text)==0 )
                Two arguments to strcmp shd. be adresses always..
                Array name is equal to its address so pass text only..
                i tried that but when debugging i am having this error

                An Access violation(segme nt fault) raised in your program.

                the line of code crushinhg the program is:



                Code:
                if (strcmp(check->words,temp)==0)

                Comment

                • arne
                  Recognized Expert Contributor
                  • Oct 2006
                  • 315

                  #9
                  Originally posted by tirivamwe
                  i tried that but when debugging i am having this error

                  An Access violation(segme nt fault) raised in your program.

                  the line of code crushinhg the program is:



                  Code:
                  if (strcmp(check->words,temp)==0)
                  It should be 'text', not 'temp', I think.

                  Comment

                  Working...