i want to read these data and put them to a array of struct but it does not work
#include<stdio.h>
struct book {
char bookName[50];
char authorName[50];
long price;
int year;
}
main() {
FILE *data;
data=fopen("library.txt", "r");
if (data == NULL) {
printf("File Could not be opened!\n");
}
else {
struct book myBook;
struct book books[20];
int n=0;
while (!feof(data))
{
fscanf(data,"%s***%s***%d***%d\n",&myBook.bookName,&myBook.authorName,&myBook.price,&myBook.year);
books[n]=myBook;
n++;
}
int i;
for(i=0;i<n;i++){
printf("%s - %s - %d - %d \n",books[i].bookName,books[i].authorName,books[i].price,books[i].year);
}
}
}
and output is
C - b - 0 - 232159429
programing***Fatemeh - b - 0 - 232159429
Kazemi***15000***1391 - b - 0 - 232159429
C - b - 0 - 232159429
programs***Ali - b - 0 - 232159429
Ahmadpour***20000***1392 - b - 0 - 232159429
Programing***Mona - b - 0 - 232159429
Ghassemi***25000***1389 - b - 0 - 232159429
C - b - 0 - 232159429
programing - b - 0 - 232159429
(advanced)***Sara - b - 0 - 232159429
Hamidi***40000***1385 - b - 0 - 232159429
but my real data is
C programing***Fatemeh Kazemi***15000***1391
Cprograms***Ali Ahmadpour***20000***1392
Programing***Mona Ghassemi***25000***1389
C programing (advanced)***Sara Hamidi***40000***1385
what should i do? it looks fscanf only works with spaces but i need to use *** to seperate my data