how to insert multiple characters into a string in C [closed]
- by John Li
I wish to insert some characters into a string in C:
Example:
char string[20] = "20120910T090000";
I want to make it something like "2012-09-10-T-0900-00"
My code so far:
void append(char subject[],char insert[], int pos) {
char buf[100];
strncpy(buf, subject, pos);
int len = strlen(buf);
strcpy(buf+len, insert);
len += strlen(insert);
strcpy(buf+len, subject+pos);
strcpy(subject, buf);
}
When I call this the first time I get:
2012-0910T090000
However when I call it a second time I get:
2012-0910T090000-10T090000
Any help is appreciated