Thread: assignment makes pointer from integer without a cast

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    3

    assignment makes pointer from integer without a cast

    Hello,

    I'm hoping someone can explain this warning to me. I'm sure it's just something I'm not aware of!

    Code:
    if ((infile = fopen("/src/infile", "r")) == NULL) {
    		printf("Couldn't Open File");
    		exit(1);
    	} else {
    
    		/*READ CHARS INTO THE MM STORAGE*/
    		char c;
    		char d;
    
    		do{
    			c = fgetc(infile);
    			//printf("%c\n", c);
    			if(c != '\n')
    			{
    			d = fgetc(infile);
    			MM[I_COUNTER] = c; //<---Warning Here
    			I_COUNTER++;
    			MM[I_COUNTER] = d; //<---Warning Here
    			I_COUNTER ++;
    			}
    		} while((c != 'D') && (d != 'A'));
    
    		int k = 0;
    		while(k < 4){
    			c = fgetc(infile);
    			k++;
    		}
    
    		//RESET OUR INSTRUCTION COUNTER
    		I_COUNTER = 0;
    		STACK_POINTER = 240;
    	}
    Thanks!

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    #1. What is MM? How is it defined?

    #2. fgetc returns an int, not a char.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    it is assumed from other parts of your code that MM should have been declared as either a char pointer and then sized, or should have been declared as fixed storage like char MM[10]
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  4. #4
    Registered User
    Join Date
    Aug 2010
    Location
    Rochester, NY
    Posts
    196
    Quote Originally Posted by rogster001 View Post
    it is assumed from other parts of your code that MM should have been declared as either a char pointer and then sized, or should have been declared as fixed storage like char MM[10]
    Yeah, but that's where the error is, so assumptions are all off.

    @ OP: Indeed, what is the declaration of MM, it's not a double pointer by any chance, is it?

    It's not defined like:
    Code:
    char** MM;
    or
    Code:
    char* MM[#];
    Is it? Both cases are double pointers, or arrays of pointers (same thing), the bracket operator will dereference ONE, returning a pointer. It assumes if you're setting a pointer equal to a character, you're doing something wrong.

    Can you copy/paste the line it is declared on?

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Syndacate View Post
    Is it? Both cases are double pointers, or arrays of pointers (same thing), the bracket operator will dereference ONE, returning a pointer. It assumes if you're setting a pointer equal to a character, you're doing something wrong.
    They are not the same thing, but they will yield the same problem in this case.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 08-11-2009, 12:09 PM
  2. pointers, structures, and malloc
    By lugnut in forum C Programming
    Replies: 24
    Last Post: 10-09-2008, 04:52 PM
  3. Pointer from integer without cast
    By STDSkillz in forum C Programming
    Replies: 2
    Last Post: 10-22-2007, 09:39 PM
  4. assignment makes pointer from integer
    By crescen7 in forum C Programming
    Replies: 4
    Last Post: 06-25-2002, 10:08 PM
  5. Replies: 3
    Last Post: 01-14-2002, 12:13 PM