Strcmp error

This is a discussion on Strcmp error within the C Programming forums, part of the General Programming Boards category; What is the meaning of this warning 'passing arg 1 of `strcmp' makes pointer from integer without a cast' The ...

  1. #1
    Ron
    Ron is offline
    Registered User
    Join Date
    May 2006
    Posts
    151

    Post Strcmp error

    What is the meaning of this warning

    'passing arg 1 of `strcmp' makes pointer from integer without a cast'

    The code in that line is as follows:

    Code:
    if   (strcmp(checkelement,stackP->contents)==0)
        return stackP->contents[stackP->top--];

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Show us where checkelement is defined.

    Basically its saying that checkelement is an integer instead of a pointer to char like it's suppose to be.

  3. #3
    Ron
    Ron is offline
    Registered User
    Join Date
    May 2006
    Posts
    151

    Post

    I have defined checkelement in another class with the variable name check

    Code:
    char check[10];

  4. #4
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,522
    So show us what checkelement looks like please. A character string called check is completely different from whatever checkelement is supposed to be. Pretty much if checkelement isn't a character string you lose.

  5. #5
    Ron
    Ron is offline
    Registered User
    Join Date
    May 2006
    Posts
    151
    Well let me explain, what I tried doing. There was a character string named element. I needed to omit certain characters from the content of 'element' and copy the rest into the 'check' variable


    Code:
    char *temp;
    *temp=element[2]; // Copy initiates from the 3rd letter in the  
                                        element array
    k=0;
    while(k<=strlen(element)-3) // This will not copy the last 
                                                     character  in the element array
    check[k++]=putchar(*temp++);
    Then I pass the check into a function which is defined in another file.

  6. #6
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    So what is checkelement?
    Code:
    if   (strcmp(checkelement,stackP->contents)==0)
        return stackP->contents[stackP->top--];
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  7. #7
    Ron
    Ron is offline
    Registered User
    Join Date
    May 2006
    Posts
    151
    checkelement == check.

    As i said before, passed check as an input variable into a function.

    While defining the function, I named it check as check element.

    Still confused. Forget the check. treat everything as checkelement.

  8. #8
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    If you're not going so show something like:
    Code:
    char checkelement[19];
    you are simply trying to avoid an anwser. We're only asking the same thing as your compiler.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  9. #9
    Ron
    Ron is offline
    Registered User
    Join Date
    May 2006
    Posts
    151
    This is the code in the main function and in the function

    Main function:
    Code:
    char check[10];
    char element[10];
    
    while (scanf("%s",code)!=EOF)
    {
    
            ++line;
             while (i<strlen(code))
             {
    	c=code[i];
    
                     if (c == '<')
    	 {
    
    	       j=0;
    	        do
    	       {
    		element[j++]=c;
    		code[i++];
    	        }while(c!='>');
    
    	        *temp=element[2];
    	        k=0;
    	       while(k<=strlen(element)-3)
    	       check[k++]=putchar(*temp++);
    	       Pop(&s1, check,line);

    Pop function:

    Code:
    stackElement Pop(stackST *stackP, char checkelement, int line)
    {
    
               if	(strcmp(checkelement,stackP->contents)==0)
        return stackP->contents[stackP->top--];
    }
    These are just snippets of the whole code. So according to the above code, there is no need to declare a variable checkelement, as it was passed from the main function. WHy is it giving me a warning as such for the strcmp function:
    ' warning: passing arg 1 of `strcmp' makes pointer from integer without a cast'

    I hope now my question is clear. If not, I shall explain again.

  10. #10
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Code:
    stackElement Pop(stackST *stackP, char checkelement, int line)
    {
               if	(strcmp(checkelement,stackP->contents)==0)
        return stackP->contents[stackP->top--];
    }
    checkelement needs to be a char *, as previously mentioned.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  11. #11
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,522
    Aha, see, now we can answer the question. Main passes the check string by value, so checkelement is not a character pointer. What you ought to have is something like this as a parameter list.
    Code:
    stackElement Pop(stackST *stackP, char *checkelement, int line)
    And in main, pass the address of check.
    Code:
    Pop(&s1, &check, line);

  12. #12
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,045
    Code:
                     if (c == '<')
    	 {
    
    	       j=0;
    	        do
    	       {
    		element[j++]=c;
    		code[i++];
    	        }while(c!='>');
    That's not very good indentation. The line marked in red doesn't do anything except increment i. The whole loop there only executes once, because c is never changed. Perhaps you meant to switch the two sides of the line marked in blue?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  13. #13
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,045
    Quote Originally Posted by citizen
    Aha, see, now we can answer the question. Main passes the check string by value, so checkelement is not a character pointer. What you ought to have is something like this as a parameter list.
    Code:
    stackElement Pop(stackST *stackP, char *checkelement, int line)
    And in main, pass the address of check.
    Code:
    Pop(&s1, &check, line);
    Why should main call Pop() like that? check is a pointer, and according to your modification, Pop takes a pointer. main() should call Pop() like this, with no & on check:
    Code:
    Pop(&s1, check, line);
    [edit] The first part of your post is correct, though, and echos what Dave_Sinkula said. [/edit]
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  14. #14
    Ron
    Ron is offline
    Registered User
    Join Date
    May 2006
    Posts
    151
    OK im getting one more error while compiling

    Undefined first referenced
    symbol in file
    main /usr/sfw/lib/gcc/sparc-sun-solaris2.10/3.4.3/crt1.o
    ld: fatal: Symbol referencing errors. No output written to a.out
    collect2: ld returned 1 exit status

    ...
    THere is no line number given.What does this mean?

  15. #15
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    I believe this is continued here:
    Do not understand this error
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 03:35 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  5. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21