Connecting Tech Pros Worldwide Forums | Help | Site Map

String manipulation question

Newbie
 
Join Date: Oct 2008
Posts: 22
#1: Nov 17 '08
I need to concatenate a string with a dynamic part (don't know what the %d's and it's likes are called)... And exactly the fact that I don't know the name of what I'm trying to do is what makes so hard to google it :)

What I wan't to look something like this in my head:

Expand|Select|Wrap|Line Numbers
  1. strcat(ret, "! [%d] %s", i, buf);
  2.  
The code above won't work, but what will? I don't wan't to do a dozen of strcats either...

I hope somebody will point it out :)

Thanks in advance

Needs Regular Fix
 
Join Date: Sep 2007
Location: The Netherlands
Posts: 427
#2: Nov 17 '08

re: String manipulation question


You're not looking for sprintf(), are you?
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#3: Nov 17 '08

re: String manipulation question


To augment on the previous reply: sprintf() to the end of the buffer:

Expand|Select|Wrap|Line Numbers
  1. sprintf(ret+strlen(ret), "your format string here", a, b, c, d);
  2.  
kind regards,

Jos
Newbie
 
Join Date: Oct 2008
Posts: 22
#4: Nov 17 '08

re: String manipulation question


Hi.

The sprintf function was what I was looking for, I found it myself and the problem got solved :)

Thanks anyway!
Reply