statement not working

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;
}
I haven't got the answer, but format your code so it's easier to see:

1
2
3
4
5
6
7
8
9
10
11
12
if (strcmpi(st.retadmno(), admno)==0)
{
cout << "\n\nAmission number already exist!!";
cout << "\n\nEnter another admission number";
goto y;
}
else
break;
}


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?

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.
please reply.
Why are you trying to read from a file opened for output?

And you've specifically positioned the file pointer to the end of the file. That means that a read will fail.
how to solve it??

please say...
i can mail you the whole program.i have no idea what to do.
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.
> st is an object from class student.
Paste your class declaration.

Topic archived. No new replies allowed.