I have a little problem with reading data from file. I need to read the name, lastname and phone number.
But the data is separated by '|'.
file eg
Matthew | McConaughey | 684299275
Humphrey | Bogart | 204050673
Mary | Tyler Moore | 503462885
Loretta | Young | 416211713
I wrote this function
char name[20];
char lastname[40];
int number;
while(!feof(plik)){
int hpl=fscanf(filename, "%s | %s | %d", name, lastname, &number);
}
I have problem when in the file are two-member lastname like 'Tyler Moore', then fscanf return 2
I don't know how I can read them
That is possible to use one fscanf() function ?
It is because, scanf
family functions read until space. You can use fgets to get whole line, and then parse it using function multi_tok function that is shown here: https://stackoverflow.com/a/29789623/8842262
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.