#include "stdio.h"
#include "stdlib.h"
#include "string.h"
int main(){
char storage[128]="\0";
char buffer[24];
fgets(buffer, 24, stdin);
strcat(storage, buffer);
fgets(buffer, 24, stdin);
strcat(storage, buffer);
printf("%s", storage); // line 12
return 0;
}
I am trying to see that line 12
prints "string one\0string two"
when I enter "string one"
and "string two"
on previous fgets()
lines but instead, it prints "string one\nstring two"
. As far as I know strcat()
terminates the "\0"
at the end of the first string so this code should have given me the format I wanted, but it does not. What am I doing wrong?