0

I would like to save more chars in ch[500] then it is already there. I dont want to lose the chars I've saved there before.

Something that would work like this:

ch = ch + ’nextch’;
unwind
  • 391,730
  • 64
  • 469
  • 606
Modziek
  • 61
  • 4
  • Show us some code - how did you create and initialize the array? How did you insert the characters which are already there? Is it a zero terminated C string? – Andreas Fester Nov 12 '13 at 19:52

1 Answers1

2

You can use strcat() or strncat() to Concatenate two strings.

for example

char ch[100];
 strcpy(ch,"hello");
 strcat(ch," world");  

if you want to append only one character

    char str[100];
    strcpy(str,"hello");
    char ch='a';

    char buf[2];
    sprintf(buf,"%c",ch); 
    strncat(str,sizeof str, buf);

or

    size_t length= strlen(str);
    str[strlen(str)]=ch;
    str[length+1]='\0'; 
Gangadhar
  • 10,248
  • 3
  • 31
  • 50