Jump to content

Some Help with pointer from integer cast, problem ..

- - - - -

  • Please log in to reply
3 replies to this topic

#1
toto_7

toto_7

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 295 posts
Hello,

Can anyone tell me, why getting warning on this?

main(){

printf("%d",queue_put ( queues[0], qitem_init(input)));

}


/*qitem_init(char * new_data)*/

Qitem * qitem_init(char * new_data){


	Qitem* i = (Qitem*)malloc(sizeof(struct qitem));

	i->data =(char*)malloc(strlen(new_data)*sizeof(char)+1);

	i->next = 0;

	strncpy (i->data ,new_data ,MAX_STRING_LENGTH);

	

	return i;

}

c:30: warning: passing arg 2 of `queue_put' makes pointer from integer without a cast

Help please!
Thank you

"Programming is like sex. One mistake and you have to support it for the rest of your life."

-Michael Sinz

#2
Ancient Dragon

Ancient Dragon

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 400 posts
post the queue_put() function because we have no clue what the second argument is supposed to be. Did you prototype that function before calling main() ? The compiler probably has no idea what it is either.
Visit Grandpa's Forums, a social networking forum, with family-oriented arcade games, blogs, discussion forums, and photo albums.

#3
DarkLordofthePenguins

DarkLordofthePenguins

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 409 posts
The data type for input is wrong. When you get a compiler error like that, it means the function accepts a pointer but you gave it an integer.
Programming is a journey, not a destination.

#4
toto_7

toto_7

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 295 posts
Hello,

Problem solved. Just reopen the command...Now I'm occurring new problem.

while(1) {

	printf("\nPlease make a selection,\n\n");

    printf("AddList(L),AddElement(E),DeleteElement(R),\n");

	printf("NumberOfElements(C),ShowList(P), Quit(Q): ");

    scanf(" %c",&selection);

	selection = toupper(selection);


		switch(selection){

			case 'L':

				if(count <= 10){

					queues[count] = queue_init();

					count++;

					printf(">>>New queue created.\n");

				}

				else

					printf("You reach the maximum number of queues!\n");

				break;

			case 'E':

				if(count>0){

					printf("What you would like to add?\n");

					fgets (input, MAX_STRING_LENGTH, stdin);

					input[ strlen(input) - 1] = '\0';

					queue_put ( queues[0], qitem_init(input));

				}

				else

					printf("ERROR! You can't create an element without a queue.\n");

				break;

			case 'Q':

				exit(0);

		}

	}

Here a part of my code. So is working correctly if pass 'L' but when passing 'E' and hit return(Enter) input initialise automatic to Null. If pass 'E (space) text' then initialise input = text;. How I can fix that? I mean when hit Enter passing 'E' to ask me ""What you would like to add?\n"" and the pass the text.

Thank you

"Programming is like sex. One mistake and you have to support it for the rest of your life."

-Michael Sinz




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users