Dec 14, 2018 at 9:56am UTC
fp.open("student.dat", ios::out | ios::app);
while (fp.read((char *)&st,sizeof(student)))
{
if (strcmpi(st.retadmno(), admno)==0)
{
cout << "\n\nAmission number already exist!!";
cout << "\n\nEnter another admission number";
goto y;
}
else
break;
}
Dec 14, 2018 at 11:17am UTC
Why are you trying to read from a file opened for output?
> if (strcmpi(st.retadmno()
What kind of a thing is 'st' ?
Is it just a 'C' style struct containing only 'plain-old-data' such as chars, ints, floats (and arrays of those).
Or is it something more complicated, containing C++ objects, or even just pointers?
Dec 14, 2018 at 1:09pm UTC
this is a segment from a library management system.st is an object from class student.what i am trying to do is read all the existing admission numbers to compare with the newly entered admission number so that repetition does not take place.
i have very less knowledge in files.if there is a better statement to achieve the condition please reply.
Dec 14, 2018 at 2:39pm UTC
how to solve it??
please say...
Dec 14, 2018 at 2:41pm UTC
i can mail you the whole program.i have no idea what to do.
Dec 14, 2018 at 3:23pm UTC
just change how you open the file
fp.open("student.dat"); //I think this works.
try to avoid gotos.
bool y = true;
while (y && fp.read((char *)&st,sizeof(student)))
if(...)
{
stuff
y = false;
}
old goto label was here (guessing):
and here is where you resume once you break or set y to false.
Dec 14, 2018 at 4:34pm UTC
> st is an object from class student.
Paste your class declaration.