Thread: integer to pointer without cast

  1. #1
    Registered User
    Join Date
    Dec 2009

    integer to pointer without cast[Solved]

    int criar_contacto()
    	char name[33], bday[11];
    	int cell_phone;
    	printf("Introduza o Nome do contacto:\n");
    	get_string(name, 33);
    	printf("%s", name); // This is just for test purpose
    	return 1;
    void get_string(char *string_to_get, size_t string_size)
    	int i;
    	fgets(*string_to_get, string_size, stdin);
    	for(i=0; i<string_size; i++)
    So the first obvious problem here is in "get_string", Eclipse(A linux C SDK) is telling me that "passing argument 1 of ‘fgets’ makes pointer from integer without a cast".

    I've got no idea of what it means, I've googled it though, found many things about it but I didn't managed to figure it out by myself.

    The code compiles flawlessly, but when I use criar_contacto() which calls get_string() my app just terminates. My main() is just a switch case to create a menu where each case calls a fuction.

    My get_string is suposed to get a string with fgets and then cut the "\n" from it, so I don't always have to write the loop to have it done.

    I'm trying to make a "notebook for cell phone numbers" (I'm portuguese so I guess that's not what you guys call it, but i hope you get it).

    Thanks in advance,

    Hugo Ribeira
    Last edited by eidgeare; 12-08-2009 at 03:13 PM.

  2. #2
    Registered User
    Join Date
    Apr 2006
    You want:
    	fgets(string_to_get, string_size, stdin);
    The error is because you are passing the first char in string_to_get instead of the whole string. Char is an integer type, the string is a pointer type. Ergo conversion from integer to pointer without a cast.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  3. #3
    Registered User
    Join Date
    Dec 2009
    It works now, but I don't understand why.

    what goes in that argument is name[], right? which acts as a pointer, so shouldn't I call the argument type a pointer as well?

    EDIT: Understood, thank you.
    Last edited by eidgeare; 12-08-2009 at 03:11 PM.

  4. #4
    Registered User
    Join Date
    Sep 2006
    What goes in that argument is a pointer to a string - not a char pointer to a pointer to a string.

    Use string_to_get, just like you would use name.
    Last edited by Adak; 12-08-2009 at 03:16 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 08-11-2009, 12:09 PM
  2. Replies: 17
    Last Post: 08-07-2009, 11:52 AM
  3. pointers, structures, and malloc
    By lugnut in forum C Programming
    Replies: 24
    Last Post: 10-09-2008, 04:52 PM
  4. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  5. Pointer from integer without cast
    By STDSkillz in forum C Programming
    Replies: 2
    Last Post: 10-22-2007, 09:39 PM