473,748 Members | 7,571 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

There is some prolem in the funciton modification below. Please checkit and tell me what is worng?

void directory::modi fication()//???????????
{
clrscr();

cout<< "\n\t @@@@@@ @@@@@ @@@@@ @@@@@@ @@@@@ @ @
@@@@@@ ";
cout<< "\n\t=====@ @ @ @ @ @ @@ @
@ =====";
cout<< "\n\t=====@@@@@ @ @ @ @ @ @ @ @ @ @
@@@ =====";
cout<< "\n\t=====@ @ @ @ @ @ @ @@
@ @ =====";
cout<< "\n\t @@@@@@ @@@@@ @@@@@ @ @@@@@ @ @
@@@@@@ \n\n\n\n";
cout<<"I am inside the modification function before opening of
addressesFiile. ";
getch();
long pn;
int n,i;
ifstream inFile;
ofstream outFile;

inFile.open("ad dressesFile");
if(!inFile)
{
cout<<"\nI am inside the modification function after opening
of addressesFiile. Checking now with if";
getch();
cout<<"\n File not found!";
outFile.close() ;
exit(-1);
}
outFile.open("n ew");
cout<<"\nI am inside the modification function after just creating
new";
getch();
n=test();
if(n==0)
{
cout<<"\nI am inside the modification function. new is
empty";
getch();
cout<<"\n The file is empty. ! ";
getch();
return;
}
cout<<"\nI am inside the modification function before entering the
while loop.";
getch();
int deleteMe = 0;
while(inFile.go od())
{

inFile.read((ch ar*)&obj,sizeof (obj));
outFile.write(( char*)&obj,size of(obj));
cout<<"\nI am inside the modification function inside the while
loop and I have finished round "<<deleteMe +1;
deleteMe = deleteMe + 1;
getch();
}
cout<<"\nI am inside the modification function just outside
the while loop.";
inFile.close();
outFile.close() ;
outFile.open("a ddressesFile",i os::trunc);
inFile.open("ne w");
if(inFile.fail( ))
{
cout<<"\n Sorry! File not found !";
exit(-1);
}
char ch;
cout<<"\n Enter the Land Line Phone Number or the Contact :";
cin>>pn;
ch=cin.get();
cin.get(ch);
for(i=0;i<n;i++ )
{
inFile.read((ch ar*)&obj,sizeof (obj));
char d;
if(pn==landLine Phone)
{
//view1();
cout<<" Name : "<<obj.contactN ame<<"\n";
cout<<" Home Address : "<<obj.homeAddr ess<<"\n";
cout<<" EMAIL ADDRESS : "<<obj.email<<" \n";
cout<<" Cellular Phone Nmber : "<<obj.cellular Phone<<"\n";
cout<<" Land Line Phone Number : "<<obj.landLine Phone<<"\n
\n";

d=check("HOUSE PHONE NUMBER ");
if((d=='y') || (d=='Y'))
{
cout<<"\n Enter the new land line phone number of the
contact, please. :";
cin>>landLinePh one;
ch=cin.get();
cin.get(ch);
}
if(check("OFFIC E PHONE NUMBER ")=='Y')
{
cout<<"\n Enter the new cellular phone number of the
contact, please. :";
cin>>cellularPh one;
ch=cin.get();
cin.get(ch);
}
if(check("Name of the Contact")=='y')
{
cout<<"\n Enter the name of the contact, please. : ";
cin.getline(con tactName,20,'\n ');
}
if(check("HOME ADDRESS")=='y')
{
cout<<"\n Enter the new Home Address of the contact,
please. :";
cin.getline(hom eAddress,50,'\n ');
}
if(check("EMAIL ADDRESS:")=='y' )
{
cout<<"\n Enter the new E-mail Address of the contact,
please. :";
cin.getline(ema il,25,'\n');
}
}//the outer if ends here.
outFile.write(( char*)&obj,size of(obj));
}
outFile.close() ;
inFile.close();
}
Feb 13 '08 #1
2 1928
`Some problem' is rather vague. Anyway, here are some brief notes on
`what's wrong':

Unpopular wrote:
void directory::modi fication()//???????????
{
[...] -- many noisy lines ommited here and below
inFile.open("ad dressesFile");
outFile.open("n ew");
I'd guess, that file "new" is now empty and locked for writing in text mode.
n=test();
Hu?? What happens in test()?
if(n==0)
{
cout<<"\n The file is empty. ! ";
getch();
return;
Of course "new" is empty! So bye bye here?
}
while(inFile.go od())
{
So let's do some _binary_ I/O on _text_ files -- good luck!
inFile.read((ch ar*)&obj,sizeof (obj));
outFile.write(( char*)&obj,size of(obj));
What is obj? There are _very_ strong restrinctions, if you want to use
it like that!
}
inFile.close();
outFile.close() ;
outFile.open("a ddressesFile",i os::trunc);
inFile.open("ne w");
for(i=0;i<n;i++ )
Hu, what's n? Ahh, I see, the result of your test() above -- weird.
{
And again, binary I/O on a text file, using undefined `obj':
inFile.read((ch ar*)&obj,sizeof (obj));
Only cowards check return values -- real programmers post in c.l.c++ :)
if(pn==landLine Phone)
What's landLinePhone? Did you mean obj.landLinePho ne?
{
cout<<" Name : "<<obj.contactN ame<<"\n";
cout<<" Home Address : "<<obj.homeAddr ess<<"\n";
cout<<" EMAIL ADDRESS : "<<obj.email<<" \n";
cout<<" Cellular Phone Nmber : "<<obj.cellular Phone<<"\n";
cout<<" Land Line Phone Number : "<<obj.landLine Phone<<"\n
Ever thought of providing a suitable operator <<()? Then you may write
cout << obj;
d=check("HOUSE PHONE NUMBER ");
check()? Sorry, but I'm getting tired now.

I think, switching to binary file mode will fix one of your `some problem'.
But you should improve your coding style. And if you need more help,
you'll have to post code, that compiles and runs.

-- ralph

Feb 14 '08 #2
On Feb 14, 1:13 pm, "Ralph D. Ungermann" <use...@mloge-ungermann.de>
wrote:
`Some problem' is rather vague. Anyway, here are some brief notes on
`what's wrong':
Unpopular wrote:
void directory::modi fication()//???????????
{
inFile.open("ad dressesFile");
outFile.open("n ew");
I'd guess, that file "new" is now empty and locked for writing
in text mode.
First, until you test the status of outFile, you don't know
whether the open succeeded or not. If it didn't succeed, you
can't say anything about the file "new". If it did succeed,
then their is an empty file by that name---if the file existed
beforehand, you've emptied it, and if it didn't, you've created
it. (That's what the standard requires.) I can't see why it
would be locked, however.
while(inFile.go od())
And of course, this is NOT the way to read a file.

(I didn't even look at the code in the original posting; it was
too big and too much of a mess to be bothered with. So I don't
really know what the OP was trying to do. But looping on
"inFile.goo d()" is never correct.)
{
So let's do some _binary_ I/O on _text_ files -- good luck!
inFile.read((ch ar*)&obj,sizeof (obj));
outFile.write(( char*)&obj,size of(obj));
What is obj? There are _very_ strong restrinctions, if you want to use
it like that!
Like: it must be an array of characters (char or unsigned char).
The cast in question is a reinterpret_cas t, and any time you
need a reinterpret_cas t, you should ask yourself questions.
(Although if all he does is then write it with write(), it
almost certainly doesn't matter, since read will read it as an
array of characters, and write will write it as an array of
characters. But then, why isn't it defined as an array of
characters?)

And of course, as you point out, if you really want to do binary
I/O, you need to open the files in mode binary, and imbue the
"C" locale.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Feb 15 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2737
by: gonzalo briceno | last post by:
I have been using phplib for a while and I really like the framework except for form creation. Maybe it is me but I in my opinion there isn't a good way to create forms or should I say, everything else is so well done that the way you create forms seems to be too cumbersome, in particular making it so that a pull down menu selects a value that you assign it. In any case, does anyone know of any php based (or other readily accepted web...
1
2283
by: manish | last post by:
Hi, I am a fresher in the programming field i.e although I have done programming at the basic level but at professional level I am very new and I am facing many problems. These probllems are not taughtand I am not getting any Refrences to cope with them. ********Setting in VC++ 6.0 I don'know to apply setting for various/different projects. I am not getting basics out of it .Can u pls tell me how to make a good understanding of...
3
2966
by: fastwings | last post by:
mm the code //////makemenu.h//// class menu { public: int op; pmenu(int op,int sub = 0) { switch op {
7
3448
by: olga | last post by:
Hi, On my site, i want to pass a javascript variable to php. I know that this needs to done in a link or in a post. I want to know if there is a way i can do it with an html link. I should mention that these will be dynamically created links in php. This is an optional value so if javascript is disabled, my site will still function. the browser_width() function works correctly but when i
22
2573
by: Jeff Parker | last post by:
I have a web application that for the real estate industry. Here is one of the sites using said application. http://www.wellsre.com As you can see if you click this link here http://validator.w3.org/check?uri=http%3A%2F%2Fwww.wellsre.com This site validates just fine using the w3 validator
1
1577
by: BigAbility | last post by:
regKey = regKey.OpenSubKey("...."); regKey.SetValue("...", "value"); this code doesn't work registry modification not allow in .Net?? how should i do?
2
2267
by: Henry | last post by:
Hi all, I tried to install the php-5.1.4 on my server but failed. Kindly please help me. Below are what I have installed: 1) IBM Informix Dynamic Server Version 9.40.FC7 2) GNU_C_C++ (4.1.0) 3) Perl5-32 (D.5.8.3.D, The 32 Bit Perl Programming Language with Extensions)
1
1799
by: bylum | last post by:
prolem exception org.apache.jasper.JasperException at jsp the list exception : org.apache.jasper.JasperException org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:370) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
3
1002
by: usenet.tolomea | last post by:
I'm working on a remote object system, something kinda like Pyro. For the purposes of caching I need to be able to tell if a given dict / list / set has been modified. Ideally what I'd like is for them to have a modification count variable that increments every time the particular collection is modified. Unfortunately I can't find anything like that and since this needs to work for the regular normal list / dict / set objects subclassing...
0
8830
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9544
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9324
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8243
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3313
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2783
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.