By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,461 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

Files when calling the dispaly function some garbage value is coming

P: n/a
int main()
{
product g;
product t;
fstream k;
k.open("stock.txt",ios::app|ios::in);
int op=0;
static int count=0;
//k.open("stock.txt",ios::app,ios::in);
while(op<4)
{
clrscr();
cout<<"\n1.Enter details";
cout<<"\n2.Modify";
cout<<"\n3.Display";
cin>>op;

if(op==1)
{
g.getdata();
k.write((char*)&g,sizeof(g));
count++;
}

if(op==2)
{
int code;
cout<<"\nEnter code of product";
cin>>code;
k.seekg(0,ios::cur);
for(int i=0;i<count;i++)
{
k.read((char*)&t,sizeof(t));
if(t.retc()== code);
{
t.getdata();
k.seekp(-sizeof(t),ios::cur);
k.write((char*)&t,sizeof(t));
}
}
}
if(op==3)
{
product h;
k.seekg(0,ios::cur);
for(int i=0;i<count;i++)
{
k.read((char*)&h,sizeof(h));
h.display();
}
}
}//while
k.close();
return(0);
}

Apr 23 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
ar*****@gmail.com wrote:
int main()
{
product g;
product t;
fstream k;
k.open("stock.txt",ios::app|ios::in);
int op=0;
static int count=0;
//k.open("stock.txt",ios::app,ios::in);
while(op<4)
{
clrscr();
cout<<"\n1.Enter details";
cout<<"\n2.Modify";
cout<<"\n3.Display";
cin>>op;

if(op==1)
{
g.getdata();
k.write((char*)&g,sizeof(g));
count++;
}

if(op==2)
{
int code;
cout<<"\nEnter code of product";
cin>>code;
k.seekg(0,ios::cur);
for(int i=0;i<count;i++)
{
k.read((char*)&t,sizeof(t));
if(t.retc()== code);
{
t.getdata();
k.seekp(-sizeof(t),ios::cur);
k.write((char*)&t,sizeof(t));
}
}
}
if(op==3)
{
product h;
k.seekg(0,ios::cur);
for(int i=0;i<count;i++)
{
k.read((char*)&h,sizeof(h));
h.display();
}
}
}//while
k.close();
return(0);
}


And what is your problem? What are you expecting said code to do, and
what is said code actually doing?
Apr 23 '06 #2

P: n/a
Maybe there are someting problem about your display function?
plz show your class implementations and the errors or warnings supplied
by the compiler

Apr 23 '06 #3

P: n/a
The program compiles perfectly.the display fuction is a normal class
funtion,which displays the members

Apr 23 '06 #4

P: n/a
Arun,Please provide the compiler error messages.
And the operating system you are working with .

Apr 23 '06 #5

P: n/a
<ar*****@gmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
int main()
{
product g;
product t;
fstream k;
k.open("stock.txt",ios::app|ios::in);
int op=0;
static int count=0;
//k.open("stock.txt",ios::app,ios::in);
while(op<4)
{
clrscr();
cout<<"\n1.Enter details";
cout<<"\n2.Modify";
cout<<"\n3.Display";
cin>>op;

if(op==1)
{
g.getdata();
k.write((char*)&g,sizeof(g));
count++;
}

if(op==2)
{
int code;
cout<<"\nEnter code of product";
cin>>code;
k.seekg(0,ios::cur);
for(int i=0;i<count;i++)
{
k.read((char*)&t,sizeof(t));
if(t.retc()== code);
{
t.getdata();
k.seekp(-sizeof(t),ios::cur);
k.write((char*)&t,sizeof(t));
}
}
}
if(op==3)
{
product h;
k.seekg(0,ios::cur);
for(int i=0;i<count;i++)
{
k.read((char*)&h,sizeof(h));
h.display();
}
}
}//while
k.close();
return(0);
}


This is not a complete compilable program. For one we can't see what
product.getdata() does, nor product.display()

Please show us the smallest compilable program that demonstrates the
problem.
Apr 23 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.