Jump to content
  • 0

Syntax Help. Putting together variables to form a string.


Ninja

Question


  • Group:  Members
  • Topic Count:  54
  • Topics Per Day:  0.01
  • Content Count:  513
  • Reputation:   83
  • Joined:  08/11/12
  • Last Seen:  

Well, google-daddy didn't work. I just want to ask source experts out there for some help. I have now become a donkey figuring this one out.

char* mes = "This is a sample message";
char* temp = "{\"q\":\"\"}";
char* mes1 = malloc(strlen(temp) + strlen(mes) + 1);
snprintf(mes1, sizeof(mes1), "{\"q\":\"%s\"}", mes);
ShowInfo("\nMES1: %s\n",mes1);

The output is only this:

Capture.JPG.3c8b8121511e78692c2aa65464144ae9.JPG

It doesn't append everything in place.

I'm playing around with some 3rd party libraries and this is one thing that's blocking me to proceed. I'd really appreciate it if someone could educate me about this.

Edited by Ninja
Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  54
  • Topics Per Day:  0.01
  • Content Count:  513
  • Reputation:   83
  • Joined:  08/11/12
  • Last Seen:  

Fixed

	char* temp = "{\"q\":\"\"}";
	char *mes1 = malloc(strlen(temp) + strlen(mes) + 1);
	strcpy(mes1, "{\"q\":\"");
	strcat(mes1, mes);
	strcat(mes1, "\"}");
	ShowInfo("\nMES1: %s\n",mes1);

just a preview of what I'm trying to do.

Capture.JPG.1bf63b620459b58c0ce1941aef54232c.JPG

:)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...