473,385 Members | 1,587 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Files when calling the dispaly function some garbage value is coming

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
5 1663
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
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
The program compiles perfectly.the display fuction is a normal class
funtion,which displays the members

Apr 23 '06 #4
Arun,Please provide the compiler error messages.
And the operating system you are working with .

Apr 23 '06 #5
<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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: George Marshall | last post by:
Hi all, my question is what should I do with a pointer to be used inside a function ? The following function should take a pointer to a null terminated array of chars, do something with it, and...
3
by: Boris Condarco | last post by:
Hi gurus, I'm using excel 2000 to show data that comes from datagrid. The problem is that for any reason the asp.net application maintains the excel open, even though, i do close it. Besides,...
6
by: Amjad | last post by:
Hi, I want to make a project that calls and executes a function (VB code) made in a seperate file in the Application Folder. I know I can create the function in my project and call it internally,...
9
by: Simon | last post by:
Hi, I have written an ActiveX object to resize images and upload them to a database, this all works fine but when I close internet explorer the process iexporer.exe is still running in my task...
11
by: MikeT | last post by:
This may sound very elementary, but can you trap when your object is set to null within the object? I have created a class that registers an event from an object passed in the constructor. When...
44
by: Smokey Grindle | last post by:
I have a list box on my form, but I need to databind it to a data table that is a private member of the form's class... so I basically have Public Class MyForm priate m_MyTable as new datatable...
173
by: Marty James | last post by:
Howdy, I was reflecting recently on malloc. Obviously, for tiny allocations like 20 bytes to strcpy a filename or something, there's no point putting in a check on the return value of malloc....
4
by: tdahsu | last post by:
All, I'd appreciate any help. I've got a list of files in a directory, and I'd like to iterate through that list and process each one. Rather than do that serially, I was thinking I should...
46
by: Carlo Milanesi | last post by:
Hello, traditionally, in C++, dynamically allocated memory has been managed explicitly by calling "delete" in the application code. Now, in addition to the standard library strings, containers,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.