S
Stanley S
Hi,
I'm puzzled. Why does the following cause a seg fault? Notwithstanding
that I've already malloc() a certain space for "Hello".
I do understand that using a fixed length array will work very well.
But I wish to find out how can this be achieve using pointers.
Thank you.
Stan
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
char *Hello = NULL;
char *World = NULL;
Hello = malloc(100);
Hello = "hello";
World = "world";
strcat(Hello, World);
printf("%s\n",Hello);
return 0;
}
I'm puzzled. Why does the following cause a seg fault? Notwithstanding
that I've already malloc() a certain space for "Hello".
I do understand that using a fixed length array will work very well.
But I wish to find out how can this be achieve using pointers.
Thank you.
Stan
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
char *Hello = NULL;
char *World = NULL;
Hello = malloc(100);
Hello = "hello";
World = "world";
strcat(Hello, World);
printf("%s\n",Hello);
return 0;
}