-5

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 e.g.

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 ?

Deepshika S
  • 500
  • 4
  • 16
anocyney_
  • 1
  • 3
  • 1
    have a look at this answer on [instruct the fscanf() to look for another delimiter](https://stackoverflow.com/questions/55443267/specifying-a-format-for-fscanf-that-doesnt-contain-white-spaces) – James Li Sep 02 '19 at 09:44

1 Answers1

0

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

Miradil Zeynalli
  • 423
  • 4
  • 18