[Warning] comparison between pointer and integer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Creese
    New Member
    • Nov 2011
    • 5

    [Warning] comparison between pointer and integer

    I'm new to coding and this is the first code I've tried by myself. I keep getting this error [Warning] comparison between pointer and integer. Can anyone help me?

    Code:
    #include <stdio.h>
    #include <conio.h>
    int main(void)
    {
        int sum;
        int sum2;
        int sum3;
        int sum4;
        int sum5;
        char name;
        char france;
        char texas;
        char canada;
        char mexico;
        char houston;
        
        printf("What is your name?");
        scanf("%s", &name);
        printf("Hello, %s.\n", &name);
        getch();
            
        printf("%s, please answer the following questions: 1+1=", &name);
                    scanf("%d", &sum);
                    if (sum == 2)
                       {printf("Correct. Now try this one. 6+11=");}
                       else
                       {printf("Incorrect. The answer was 2. Now try this one. 6+11=");}
                             scanf("%d", &sum2);
                             if(sum2 == 17)
                             {printf("Correct. Now try this one. 8+2=");}
                             else
                             {printf("Incorrect. The answer was 17. Now try this one. 8+2=");}
                                                 scanf("%d", &sum4);
                                                 if (sum4 == 10)
                                                 {printf("Correct. This is the last one. I bet you wont get this one. 999+999=");}
                                                 else
                                                 {printf("Incorrect. The answer was 10. This is the last one. I bet you wont get this one. 999+999=");}
                                                                     scanf("%d", &sum5);
                                                                     if(sum5 == 1998)
                                                                     {printf("Correct. Wow, you are smart.\n What is the capital of France?");}
                                                                     else
                                                                     {printf("It was 1998...Told you you wouldn't get it.\n What is the capital of France?");}
                     scanf("%s", &france);
                                 if (france == "paris")
                                 {printf("Nice. Try this one. What is the capital of Texas");}
                                                else
                                 {printf("Sorry but %s was wrong.The correct answer was Paris. Try this one. What is the capital of Texas", france);}
        
        
        getch();
        }
    As you can see I have unused variables. I can't continue until i get this figured out.
  • Creese
    New Member
    • Nov 2011
    • 5

    #2
    I got
    Code:
            if (france = "paris")
                                 {printf("Nice. Try this one. What is the capital of Texas");}
    to work

    [Warning] assignment makes integer from pointer without a cast.
    and this part doesn't work:
    Code:
      else
                                 {printf("Sorry but %s was wrong.The correct answer was Paris. Try this one. What is the capital of Texas", france);}
    when I get it wrong it still puts the if statement

    Comment

    • YarrOfDoom
      Recognized Expert Top Contributor
      • Aug 2007
      • 1243

      #3
      I wouldn't really call that "getting it to work" as you're just trying to assign "paris" to france, you're not comparing them to each other.

      I think it might help if you read up a bit on null-terminated character arrays. [link]
      Perhaps you should also check out the assignment and equality operators again. [link]

      Comment

      • Creese
        New Member
        • Nov 2011
        • 5

        #4
        How do you do a if statement with it. I cant find it anywhere and i tried to do it myself and this is how it turned out.

        Comment

        • Banfa
          Recognized Expert Expert
          • Feb 2006
          • 9067

          #5
          You need to read up on the C string library which uses the header string.h [link]

          Comment

          • Creese
            New Member
            • Nov 2011
            • 5

            #6
            i looked at the link and i still dont understand

            Comment

            • Banfa
              Recognized Expert Expert
              • Feb 2006
              • 9067

              #7
              Did you bother to follow any of the linked and read about any of the functions listed?

              Comment

              • Creese
                New Member
                • Nov 2011
                • 5

                #8
                yes and it helped alot. Thanks

                Comment

                Working...