Code:
17:20 aluser@alf:~/C$ cat blah.c
#include <stdio.h>
#include <string.h>
int main()
{
char *b;
char login[16];
printf("Please enter some text: ");
scanf("%s", login);
printf("test 1\n");
strcpy(b, login);
printf("test 2 %s %s\n", login, b);
printf("%s\n", b);
printf("test 3\n");
return 0;
}
17:20 aluser@alf:~/C$ gcc -o blah blah.c
17:20 aluser@alf:~/C$ ./blah
Please enter some text: hello
test 1
Segmentation fault (core dumped)
you got lucky; your b happened to point somewhere valid. if you start it off as NULL or 0xffffffff, you'll get an error too.