Self-teaching C is full of surprises. I do this short snippet to test strcat()
, which supposedly appends the second parameter to the first one:
#include <stdio.h>
#include <string.h>
char s1[4] = "Foo ";
char s2[] = "Bar";
int main(void) {
strcat(s1, s2);
printf("%s %d %d \n", s1, strlen(s1), strlen(s2));
return 0;
}
I was expecting some overflow error since s1
is an array of 4 chars, but instead I got this:
Foo BarBar BarBar 10 6
I did this on Windows using MS Visual Studio Express 2013 (which by the way raise some alerts about using strcat). So... why did strcat duplicate the value of s2? That's not in the documentation.