Hello.
This simple code was nicely working:
Code:
#include <stdio.h>
#include <string.h>
int main(void)
{
char *source_str = "Some message here.\n";
char str[strlen(source_str) * 2];
int i;
strcpy(str, source_str);
for(i=0; i<5; i++)
strcat(str, source_str);
printf("%s\n", str);
return 0;
}
Then I made some changes in the string:
Code:
char *source_str = "Some message here."
" Let's make it even longer."
" Let's add another sentence.\n";
Now, when I try to run this program, system replies: "Segmentation fault"
What actually causes this an what would be the alternatives?
Thank you.