473,405 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

[Warning] comparison between pointer and integer

5
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?

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <conio.h>
  3. int main(void)
  4. {
  5.     int sum;
  6.     int sum2;
  7.     int sum3;
  8.     int sum4;
  9.     int sum5;
  10.     char name;
  11.     char france;
  12.     char texas;
  13.     char canada;
  14.     char mexico;
  15.     char houston;
  16.  
  17.     printf("What is your name?");
  18.     scanf("%s", &name);
  19.     printf("Hello, %s.\n", &name);
  20.     getch();
  21.  
  22.     printf("%s, please answer the following questions: 1+1=", &name);
  23.                 scanf("%d", &sum);
  24.                 if (sum == 2)
  25.                    {printf("Correct. Now try this one. 6+11=");}
  26.                    else
  27.                    {printf("Incorrect. The answer was 2. Now try this one. 6+11=");}
  28.                          scanf("%d", &sum2);
  29.                          if(sum2 == 17)
  30.                          {printf("Correct. Now try this one. 8+2=");}
  31.                          else
  32.                          {printf("Incorrect. The answer was 17. Now try this one. 8+2=");}
  33.                                              scanf("%d", &sum4);
  34.                                              if (sum4 == 10)
  35.                                              {printf("Correct. This is the last one. I bet you wont get this one. 999+999=");}
  36.                                              else
  37.                                              {printf("Incorrect. The answer was 10. This is the last one. I bet you wont get this one. 999+999=");}
  38.                                                                  scanf("%d", &sum5);
  39.                                                                  if(sum5 == 1998)
  40.                                                                  {printf("Correct. Wow, you are smart.\n What is the capital of France?");}
  41.                                                                  else
  42.                                                                  {printf("It was 1998...Told you you wouldn't get it.\n What is the capital of France?");}
  43.                  scanf("%s", &france);
  44.                              if (france == "paris")
  45.                              {printf("Nice. Try this one. What is the capital of Texas");}
  46.                                             else
  47.                              {printf("Sorry but %s was wrong.The correct answer was Paris. Try this one. What is the capital of Texas", france);}
  48.  
  49.  
  50.     getch();
  51.     }
  52.  
As you can see I have unused variables. I can't continue until i get this figured out.
Nov 24 '11 #1
7 3404
Creese
5
I got
Expand|Select|Wrap|Line Numbers
  1.         if (france = "paris")
  2.                              {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:
Expand|Select|Wrap|Line Numbers
  1.   else
  2.                              {printf("Sorry but %s was wrong.The correct answer was Paris. Try this one. What is the capital of Texas", france);}
  3.  
when I get it wrong it still puts the if statement
Nov 24 '11 #2
YarrOfDoom
1,247 Expert 1GB
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]
Nov 24 '11 #3
Creese
5
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.
Nov 24 '11 #4
Banfa
9,065 Expert Mod 8TB
You need to read up on the C string library which uses the header string.h [link]
Nov 24 '11 #5
Creese
5
i looked at the link and i still dont understand
Nov 24 '11 #6
Banfa
9,065 Expert Mod 8TB
Did you bother to follow any of the linked and read about any of the functions listed?
Nov 25 '11 #7
Creese
5
yes and it helped alot. Thanks
Nov 25 '11 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Dawn Minnis | last post by:
Hi When I compile my files I get the following: driver.c: In function `main': driver.c:49: warning: assignment makes integer from pointer without a cast driver.c:50: warning: assignment...
16
by: jose_luis_fdez_diaz_news | last post by:
Hi, If I don't include <libgen.h> I get then warnig below in regcmp call: warning: improper pointer/integer combination: op "=" but if I include it the warning is not shown, but them program...
4
by: metalinc | last post by:
hi...im new to C programming...need help...tried to run this code but got this error fork.c: In function ‘parse’: fork.c:44: warning: comparison between pointer and integer fork.c:51: warning:...
5
by: J.Broeden | last post by:
Hi, I've written a some code to assist in my understanding of strings using some of Cs built in character handling functions but I am not sure why I'm getting the following error. I hope someone...
2
by: jthep | last post by:
I'm creating an addrecord and a delete record for a linked list below: int addRecord(struct record **start, char name, char address, int yearofbirth, char telno) { struct record *temp; ...
1
by: woods1313drew | last post by:
The following code in c+ gives me the warning assignment makes integer from pointer without a cast. destination is set as char destination to limit the input string to 10 characters. name is an...
5
by: evanevankan2 | last post by:
I have a question about the warning 'comparison between signed and unsigned' I get from my code. It comes from the conditional in the outer for loop. I understand the warning, but I'm not sure...
3
by: nexusdarkblue | last post by:
Hello everyone, I am somewhat new to C programming (I started last year) and I'm fairly good at it so far...that is, until I've recently started working with structures. In my current program,...
3
by: Mattias | last post by:
1 #include <iostream> 2 using namespace std; 3 #include <windows.h> 4 #include <winuser.h> 5 6 int save(int key_stroke, char *file); 7 8 int main() 9 { 10 char i;
1
by: Shane Fitz | last post by:
The title is the warning I get when I try to run the following function char * setup_mutations() { char *result = malloc(sizeof(char)); int i; char c, current, string; FILE * fp; ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.