0

I need to reed a csv file in C. I made a struct like this:

typedef struct Node{
  void** elem;
  List* next;
}List;

If I dont'know what's in csv file, how can I read the elements? They can be different in the same record. A sample of a record is this: 12,ciao,45,2.4 Where i have a different type in the same record. I saw fget function yet, but it return a char* or char... I would like something more generic because I don't know what there's in the record. I will use this struct with sorting algorithm. In sorting algorithm i have a compare function like this

typedef int (*CompareFunction)(void*, void*);`

so if i can read void* on csv file and than put the element on the struct this wuold make easy the compare function.

1 Answers1

0

you can use a lot of function

read function

fgets function as you said

of course you don't know the content of your file but using a char * is the best solution

in both cases you will use a char * because it's the best way to read your file; and can convert your data to an other type really easily

for example if you read a number in your file, then you can convert it to an integer using atoi for example

RomMer
  • 909
  • 1
  • 8
  • 19