I just start learning C(optional school course). I stuck on a small problem for 2 days. So the basic idea is, I have bunch of data in a file that I want to extract. However, there are 2 formats that the data has, and the first letter on each line determines what action I need to take.
For example, the data in file looks like these:
S:John,engineer,male,30
S:Alice,teacher,female,40
C:Ford Focus,4-door,25000
C:Chevy Corvette,sports,56000
S:Anna,police,female,36
What I want to do is, after open the file, read each line. If the first letter is S, then use
fscanf(fp, "%*c:%[^,],%[^,],%[^,],%d%*c",name,job,sex,&age)
to store all variable so I can pass them to function people().
But if the first letter is C, then use
fscanf(fp, "%*c:%[^,],%[^,],%d%*c",car,type,&price)
to store so I can pass them to function vehicle().
Would really appreciated if anyone can give me some pointer on how to do this. Thanks.