I have a csv file with information where the parts of it are separated with a ",". What I want to do is take this information and store it in different struct variables but I don't know how to make it so that the information is stored there.
This is my main file:
struct items beer [100];
int main(int argc, char **argv) {
char *oneline, *tok;
char envara[512];
char delim [] = ",";
FILE *fp;
int i = 0;
fp = fopen("varor.csv", "r");
printf("ID\n");
while (!feof(fp)) {
if (fp == NULL) {
fprintf(stderr, "File varor.csv could not be opened\n");
exit(-1);
}
fgets(envara, 512, fp);
envara[strlen(envara) -1] = '\0';
printf("En rad; %s\n", envara);
oneline = strdup(envara);
tok = strtok(oneline, delim);
while (tok != NULL) {
printf("%s\n", tok);
tok = strtok(NULL,delim);
}
}
return 0;
}
And this is my struct:
struct items {
int itemnumber;
char name [100];
float price;
float volyme;
char types [100];
char style [100];
char package [20];
char country [20];
char producer [50];
float alcohol_amount;
};