Trouble reading from a file
Sorry, I know that there are a lot of similar questions but I can't seem to find what the problem is.
I am just trying to read in values from a text file. They values are separated by tabs.
I believe the problem is with fscanf. Printf will print the first string correctly but everything after that is messed up.
Code:
#include <stdio.h>
struct process {
char name;
int arrival;
int length;
int deadline;
char type;
};
int main()
{
// read in all the processes
FILE *fr; // file pointer
fr = fopen("input_2011.txt", "rt"); // open the file for reading
if (fr == NULL) perror("Error Opening File.");
else {
struct process SP1;
fscanf_s(fr,"%s,%d,%d,%d,%s", &SP1.name, &SP1.arrival, &SP1.length, &SP1.deadline, &SP1.type);
printf("%s,%d,%d,%d,%s\n", &SP1.name, SP1.arrival, SP1.length, SP1.deadline, &SP1.type);
}
fclose(fr);
return 0;
}
Thank you for any help you can offer.