The problem is with this statement:
scanf("%s", &target);
You need to pass in a pointer to a buffer for the input string, not a pointer to a char *
. Replace it with something like:
target = (char *)malloc(1000);
scanf("%s", target);
Of course, this is not secure code since the user's input could exceed 1000 characters. But let's get the basics right first.