Why this doesn't work?! It compiles.
Code:
void readString(char *s);
int main() {
char *str;
readString(str);
printf("\n %s \n", str);
fflush(stdin);
getchar();
return 0;
}
void readString(char *s) {
char *temp;
// allocate space for temp string
temp = (char *) malloc(100 * sizeof(char));
// read in temp
scanf("%s", temp);
// allocate space in the target string
s = (char *) malloc( (strlen(temp)+1) * sizeof(char));
// memcpy temp to the target string
memcpy(s, temp, strlen(temp)+1);
// free temp
free(temp);
}