Hi, I have a text file with a list that reads like this: Last name, First name, Grade with the names being strings and the grades being integers. I need to put this list into a structure so that I can manipulate the list using any of the three sections. I know that using strtok and setting the delimiter as the comma will cut the list into the pieces I need, but I don't know how to put each piece into a separate area of the structure. This is what I have so far:
Code:
#include <stdio.h>
#include <string.h>
//Create the structure
typedef struct{
char last_name[30];
char first_name[20];
float grade;
} class_data;
main() {
FILE fp*;
fp = fopen(file, "r");
//Find the length of the list
int i = 0;
while(fgets(string, 75, fp)!=NULL) {
i++;
}
class_data student[i];
int counter;
char token[30];
for(counter=0; counter<i, counter++) {
while(fgets(string, 75, fp)!=NULL) {
token = strtok(string, ",");
Can anybody give me some guidance on how to put the information into the structure? As soon as I get that worked out, the rest will be easy but I can't find anything like this online. Thank you!