What would be the possible reason why my code display two reasults whenever i search for a record that is in the second row or higher, first it display the first records and then it display the record i am searching.
example output:
->Enter ISBN : A200
then the output would become:
->Book Number : A100
->Book Title : The_Book_of_life
->Author : Me
->Book Number : A200
->Book Title : My_House
->Author : You
then with an experiment I add put a value for X which is X=5, then it works! but i don't know the reason why, i just need some explanation... thanks in advance..
hears my record data... and my code...
A100 The_Book_of_life Me
A200 My_House You
A400 The_jurney_to_the_west Philip
A300 Ghost Matrical
# Heading Here #
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
FILE * txtFile;
char ISBN[50], Data[50];
int txtScan=1, recScan;
int x, rate;
int main()
{
clrscr();
cout << "\n\n\tEnter ISBN : ";
cin >> ISBN;
txtFile = fopen("Book.txt","r+");
if (txtFile != NULL)
{ do {
txtScan = fscanf(txtFile, "%s", Data);
recScan = strcmp(Data,ISBN);
if (recScan == 0) { x=1; }
if (x==1)
{ cout << "\nBook Number : " << Data; }
else if (x==2)
{ cout << "\nBook Title : " << Data; }
else if (x==3)
{ cout << "\nAuthor : " << Data;}
x = x + 1;
}
while(txtScan != EOF);
}
fclose(txtFile);
getch();
}
another thing, how could i display an output like the one below without altering the textfile...
sample output:
->Book Title : My_House
->Book Number : A200
->Author : You
it will display first the book title before the ISBN number.