Originally Posted by
the bassinvader
This works fine however it also includes the \0 on the end of the
shorter string.
Are you sure? It shouldn't. The function strcat() copies over the null at the end of the string being copied to.
Code:
#include <stdio.h>
#include <string.h>
int main(void) {
char sString[] = "Hello";
char lString[41];
strcpy(lString,sString);
while(strlen(lString) + strlen(sString) < 40) {
strcat(lString, sString);
}
printf("%s", lString);
return 0;
}
/*
[H][e][l][l][o][\0] ... strcpy ...
[H][e][l][l][o][\0] ... giving you ...
[H][e][l][l][o][H][e][l][l][o][\0]
*/
...and a billion people already replied. Note to self: Write shorter examples.