V
Vasilis Serghi
Hi all, I am fairly new to C programming and I have come to a stand still. I
am trying to create a program that will accept a user input and give the
user an output depending on the contents of a csv file. So far I have
successfully managed to capture the user input, open the csv file, create a
structure that matches the file data, but I cannot get the data into the
structure to do a search on.
This is some of what I have done so far:-
#define NUM_OF_ROWS 437
#define NUM_OF_COLUMNS 3
FILE *errorFile;
struct csvFileData {
char dtcDesc[NUM_OF_ROWS];
int errorNum[NUM_OF_ROWS];
char dtcNum[NUM_OF_ROWS];
}dtcInfo;
if ((errorFile = fopen("Error_Loc.csv","r")) == NULL)
{
fprintf(stderr,"\nError opening \"Error_Loc.csv\" file. \
\nMake sure the file is in the same folder as this program.
\nProgram will now exit. ");
system("PAUSE");
exit(1);
}
fclose(errorFile);
I assume that as I didn't get the error for fprintf, then the file was
opened and closed ok.
My question is, how do I get the contents of the errorFile into my
structure?
If the user selects 14 as an error number for example, how can I do the
search on the structure to give me back the dtcInfo.dtcDec and
dtcInfo.dtcNum that corresponds to the error number requested?
How can I initialise the structure with zeros for the int and spaces for
char?
Again sorry if this is basic stuff. Any help is greatly appreciated.
am trying to create a program that will accept a user input and give the
user an output depending on the contents of a csv file. So far I have
successfully managed to capture the user input, open the csv file, create a
structure that matches the file data, but I cannot get the data into the
structure to do a search on.
This is some of what I have done so far:-
#define NUM_OF_ROWS 437
#define NUM_OF_COLUMNS 3
FILE *errorFile;
struct csvFileData {
char dtcDesc[NUM_OF_ROWS];
int errorNum[NUM_OF_ROWS];
char dtcNum[NUM_OF_ROWS];
}dtcInfo;
if ((errorFile = fopen("Error_Loc.csv","r")) == NULL)
{
fprintf(stderr,"\nError opening \"Error_Loc.csv\" file. \
\nMake sure the file is in the same folder as this program.
\nProgram will now exit. ");
system("PAUSE");
exit(1);
}
fclose(errorFile);
I assume that as I didn't get the error for fprintf, then the file was
opened and closed ok.
My question is, how do I get the contents of the errorFile into my
structure?
If the user selects 14 as an error number for example, how can I do the
search on the structure to give me back the dtcInfo.dtcDec and
dtcInfo.dtcNum that corresponds to the error number requested?
How can I initialise the structure with zeros for the int and spaces for
char?
Again sorry if this is basic stuff. Any help is greatly appreciated.