So in the following function...I want to store the string, that the user enters, into the pointer variable targetFile. I am getting the following warning and when I execute it, I get a segmentation fault.
warning
My Code is below
void findFile()
{
char *targetFile;
printf("Enter the complete file name that you wish to search: ");
scanf("%s", &targetFile);
printf("\n");
}
I know I could have done the following, which works perfectly fine, but I don't know how large the targetFile character array will be. Just manually entering in 50 seems like bad practice. Can someone tell me the best approach? Thank you!
void findFile()
{
char targetFile[50];
printf("Enter the complete file name that you wish to search: ");
scanf("%s", targetFile);
printf("\n");
printf("%s\n", targetFile);
}