I want 2 strings to combine together.
First, I tried this one is OK.
#include <stdio.h>
#include <string.h>
int main(int argc, const char * argv[])
{
char a[100] = "0";
char b[100] = "1";
//char *a = "0";
//char *b = "1";
printf("%s\n", a);
printf("%s\n", b);
strcat(a,b);
printf("%s\n", a);
return 0;
}
///////////////////////////
0
1
01
But, the second caused the problem. I can't figure out where not correct is.
#include <stdio.h>
#include <string.h>
int main(int argc, const char * argv[])
{
//char a[100] = "0";
//char b[100] = "1";
char *a = "0";
char *b = "1";
printf("%s\n", a);
printf("%s\n", b);
strcat(a,b);
printf("%s\n", a);
return 0;
}
///////////////////////////
0
1
Segmentation fault
I have no idea why... Could somebody explain it ... please?