Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Some Help with pointer from integer cast, problem ..


  • Please log in to reply
3 replies to this topic

#1 toto_7

toto_7

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 244 posts

Posted 07 November 2011 - 03:25 PM

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
  • 0

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

-Michael Sinz

#2 Ancient Dragon

Ancient Dragon

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 378 posts

Posted 07 November 2011 - 07:26 PM

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.
  • 0
Visit Grandpa's Forums, a social networking forum, with family-oriented arcade games, blogs, discussion forums, and photo albums.

#3 DarkLordCthulhu

DarkLordCthulhu

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 422 posts
  • Location:The bash shell
  • Programming Language:C, JavaScript, Bash, Others
  • Learning:Ruby, Others

Posted 08 November 2011 - 05:41 AM

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.
  • 0
Programming is a journey, not a destination.

#4 toto_7

toto_7

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 244 posts

Posted 08 November 2011 - 12:53 PM

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
  • 0

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

-Michael Sinz




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download