Stupid C problem

Soldato
Joined
22 Oct 2005
Posts
2,860
Location
Moving...
I've got a really simple problem but I cant work it out. I'm using straight C.

I need to make a string that will be in the form A555.txt where A is a letter and 5's are digits.

So i've defined a string like; char myString[8];
I can set the letters and the .txt extension by doing:
myString[0] = 'A'
myString[4] = '.'
myString[5] = 't' etc

But the digits are proving to be a problem. I've got an integer variable that will be 3 digits long that I want to put into the string in locations 1,2 and 3, but I cant do it. How can I put it into my string?

Sorry for the stupid question and thanks for any advice.
 
I'd use sprintf to construct the string...
Code:
char myString[8];
int i = 555;
sprintf(myString, "A%3d.txt", i);
 
Last edited:
Back
Top Bottom