I'm trying to learn C. So I've challenged myself to create a function called two()
which will effectively "double" a string.
two("foo") // => "foofoo"
But I'm having trouble using strcat()
in conjunction with pointers. Here's what I have:
char *two(char *foo);
int main() {
printf("The value of two(\"foo\") is %s", two("foo"));
}
char *two(char *foo) {
return strcat(foo, foo);
}
It compiles but errors on run. Why?
I have a feeling the error resides in using strcat
with pointer strings.