I'm basically just taking a string and appending / concatting with another string. The first run through produces the desired results, but the 2nd, 3rd and so on results seem to be doubling the src string. Combining things with jQuery is super simple, not sure whats going on here in C. Should I be using memset? or calloc?
#include <stdio.h>
#include <string.h>
int main(void) {
const char* name = "Michelle";
char *ptr;
char dest[30];
char yourName[30];
char dots[] = "..";
int i;
for (i=0;i<4;i++)
{
if (strlen(name) > 5)
{
sprintf(yourName, "%s", name);
strncpy(dest, yourName, 3);
ptr = strcat(dest, dots);
sprintf(yourName, "%s", ptr);
printf("%s\n", yourName);
}
}
return 0;
}
I'm expecting to see results such as
Michelle becomes Mic.. This works, however if my name structure has 4 names and they were all Michelle the results are...
Mic..
Mic....
Mic......
Mic........