Warning: assignment makes integer from pointer without a cast

This is a discussion on Warning: assignment makes integer from pointer without a cast within the C Programming forums, part of the General Programming Boards category; Hey everybody. I'm trying to make a simple calculator program and I got "warning: assignment makes integer from pointer without ...

  1. #1
    Third Eye Babkockdood's Avatar
    Join Date
    Apr 2010
    Posts
    352

    Warning: assignment makes integer from pointer without a cast

    Hey everybody. I'm trying to make a simple calculator program and I got "warning: assignment makes integer from pointer without a cast" four times on lines 17, 19, 21, and 23. Here's the source.
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
    	int int1;
    	int operate;
    	int int2;
    	int presult = (int1 + int2);
    	int mresult = (int1 - int2);
    	int xresult = (int1 * int2);
    	int dresult = (int1 / int2);
    
    	printf("Input: ");
    	scanf("%i%s%i", &int1, &operate, &int2);
    	
    	if (operate = "+")
    		printf("Result: %i\n", presult);
    	if (operate = "-")
    		printf("Result: %i\n", mresult);
    	if (operate = "*")
    		printf("Result: %i\n", xresult);
    	if (operate = "/")
    		printf("Result: %i\n", dresult);
    	
    	return 0;
    }
    I have no clue what the problem is. Can someone help?

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    1. operate is an integer.
    2. "+" is a string.
    3. = is assignment.
    4. == is an equality test.
    5. You can't test strings for equality using ==.
    6. You can't assign strings to integers.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Third Eye Babkockdood's Avatar
    Join Date
    Apr 2010
    Posts
    352
    OK, I replaced int operate; with char *operate; and it compiled without error. But when I start it, I get "Floating point exception".
    Last edited by Babkockdood; 04-24-2010 at 04:40 PM.

  4. #4
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,528
    Quote Originally Posted by Babkockdood View Post
    OK, I replaced int operate; with char *operate; and it compiled without error. But when I start it, I get "Floating point exception".
    For one thing, that does not allocate any actual space for whatever string scanf might read in. I doubt that making just one change would allow it to compile without error. What compiler are you using, and what sort of warnings have you got turned on. What does your updated code look like now?
    Last edited by kermit; 04-24-2010 at 04:53 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-20-2009, 11:37 PM
  2. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  3. assignment makes pointer from integer
    By crescen7 in forum C Programming
    Replies: 4
    Last Post: 06-25-2002, 10:08 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 3
    Last Post: 01-14-2002, 11:13 AM

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