So, I'm just trying to figure out exactly how malloc works. Here's the code I'm using to test.
char* line2;
line2 = malloc(4*sizeof(char));
fgets(line2,100,stdin);
printf("%s\n",line2);
So, I'm initializing the line to what I believe is a size of 4. Then I'm using fgets to put 99 characters in my line2. I was expecting that to crash since I was under the impression that the array set by malloc pointed by line 2 has a size of 4. However, when I input a string with more than 4 characters I get that same string. How is that happening?