if i run 1 data, program execution is success. but in 2 data format file incorrect. where did i go wrong?
File .txt
1,Nanggroe Aceh Darussalam,Rumah Sakit,RSU Cut Nyak Dhien,Jl. Tm Bahrum No. 1 Langsa
2,Jawa Barat,Klinik Utama,dr. Sunarhadi,Raya Cikaret No. 12
Read code
do{
read = fscanf(file,
"%d,%100[^,],%100[^,],%100[^,],%100[^,]\n",
&students[records].no,
students[records].prov,
students[records].tipe,
students[records].nama,
students[records].alamat);
if (read == 5) records++;
if (read != 5 && !feof(file)){
printf("File format incorrect.\n");
return 1;
}
if (ferror(file)){
printf("Error reading file.\n");
return 1;
}
} while (!feof(file));
Output says
File format incorrect.
How can i output like
No : 1
Prov : Nanggroe Aceh Darussalam
Tipe : Rumah Sakit
Nama : RSU Cut Nyak Dhien
Alamat : Jl. Tm Bahrum No. 1 Langsa
No : 2
Prov : Jawa Barat
Tipe : Klinik Utama
Nama : dr. Sunarhadi
Alamat : Raya Cikaret No. 12