Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I add a char to my string?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
How can I add a char to string?
 
couple of options. if you have a buffer that can fit the new character

char buffer[128];
strcpy(buffer,"HELLO WORLD");


you could just do

char newCharacter = '!';
buffer[strlen(buffer)] = newCharacter;
buffer[strlen(buffer)] = 0; // REQUIRED

or you could do

char Hello[] = "hello world";

char buffer[128];
sprintf(buffer,"%s%c",Hello,'!');

Just a couple of ways... there are many.

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top