For some reason, my second character array (var2) merges with the first one (var1). Here is my code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main()
{
char var1[5] = "Hello";
char var2[5] = "World";
printf("This program can write:\t%s\t%s\n", var1, var2);
getch();
return 0;
}
after compiling it, I got the following print:
This program can write: Hello WorldHello
When I changed the code to printf("This program can write:\t%s\n", var2);
I got the following print:
This program can write: WorldHello
So It's clear that that var1 is merging with var2.
Is this some kind of compiler bug. If so, how can I fix it? I tried reinstalling MINGW, but I'm still getting the same results.
Thanks a lot