So I am working on a class assignment and I have the basic program down but I am trying to go above and beyond the assignment. I have load from a predefined .dat file but I want to also give the user the option to define their own .dat file so here is my code so far:
#include <stdio.h>
#include <stdlib.h>
int main()
{
//Loads Variables
FILE *inputFile;
char *firstName[15];
char *lastName[15];
char choice[15];
printf("Welcome Friend File Importer\n");
printf("What is the name of the file you want imported:\n");
scanf("%s",&choice);
printf("you entered %c\n",choice);
if (choice == NULL)
{
printf("Friends.dat Loaded By Default\n");
choice = "friends.dat";
}
inputFile = fopen(choice, "r"); //Loads Input File
//If there is an issue then let the user know
if (inputFile == NULL)
{
printf("You got some issues... check to make sure the file exists.\n\n");
system("pause");
return -1;
}
//Starts to print out the friends list
printf("\nYour friends\n\n");
fscanf(inputFile, "%s%s", firstName, lastName);
while (!feof(inputFile))
{
printf("%s %s\n", firstName, lastName);
fscanf(inputFile, "%s%s", firstName, lastName);
}
fclose(inputFile);
system("pause");
return 0;
}
So I am wondering if the issue is because I am using scanf or is because I am trying to assign a variable inside of an if statement. Please talk to me like I am five I have dyslexia and learn better by doing then by reading.