Click here to Skip to main content
16,007,443 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Peculiar compiling differences. Pin
Michael Dunn14-May-01 16:01
sitebuilderMichael Dunn14-May-01 16:01 
GeneralRe: Peculiar compiling differences. Pin
David Fleming17-May-01 18:46
David Fleming17-May-01 18:46 
GeneralRe: Peculiar compiling differences. Pin
Michael Dunn17-May-01 18:59
sitebuilderMichael Dunn17-May-01 18:59 
GeneralRe: Peculiar compiling differences. Pin
David Fleming17-May-01 19:58
David Fleming17-May-01 19:58 
GeneralRe: Peculiar compiling differences. Pin
13-May-01 22:13
suss13-May-01 22:13 
QuestionCLongBinary --> CBitmap? Pin
13-May-01 4:44
suss13-May-01 4:44 
GeneralIn ActiveX Component MS Winsock Ver 6I can't senddata from server to client by client use getdata function but it can't receive data. Pin
12-May-01 19:09
suss12-May-01 19:09 
GeneralNeed code for Address Book... Pin
Ting12-May-01 12:08
Ting12-May-01 12:08 
Hi. I am trying to finish this code for an address book using a struct. Can someone please correct my code. If anyone wishes to help please run the program and you will see what my problem is.
After the user makes an entry (with choice 1), it should be able to display (with choice 2). My display function is not working. I am not doing something right. I need help with that, please, anyone Smile | :) ! Also, if the user enters more than one entry, the display function should display these entries one at a time. The user will hit enter to display the next entry. And so forth. Here is my code:

const char FILENAME[80] = "C:\\MS Visual C++\\Programs\\AddressBooktest.dat";
struct addresstype
{
char lastname[21];
char firstname[21];
char line1[31], line2[31], line3[31], line4[31];
char phone[14];
};

int menu();
void add_to_address_book(struct addresstype &);
void output_info(struct addresstype &, ofstream &);
void input_info(struct addresstype &);
void display_address_book(struct addresstype);

void main()
{
struct addresstype addin;
int choice=0;
ofstream outfile;

outfile.open(FILENAME, ios::out);
if(outfile.fail())
{
cout<<endl;
cout<<filename<<"="" could="" not="" be="" opened="" for="" output."<<endl;=""
cout<<"the="" file="" might="" corrupted."<<endl;=""
exit(1);=""
}=""
else=""
{=""
while(choice!="3)"
choice="menu();"
if(choice=""> 3)
{
system("cls");
cout<<"\t\t" << "INVALID ENTRY"<<endl<<endl<<endl;
}=""
else=""
{=""
switch(choice)=""
case="" 1:="" add_to_address_book(addin);=""
output_info(addin,="" outfile);=""
break;=""

case="" 2:=""
input_info(addin);=""
display_address_book(addin);=""
outfile.close();=""

int="" menu()=""
int="" choice="0;"
cout<<endl<<endl;=""
cout<<"\t\t"="" <<="" "what="" do="" you="" want="" to="" do?"<<endl<<endl;="" "1.="" add="" an="" entry"<<endl;="" "2.="" display="" entries"<<endl;="" "3.="" exit"<<endl;=""
cout<<endl<<endl<<endl;="" "enter="" your="" (1,="" 2="" or="" 3):="" ";=""
cin="">>choice;
return choice;
}

void add_to_address_book(addresstype& addin)
{
system("cls");

cout<<endl<<endl;
cin.ignore(100,="" '\n');=""
cout<<"\t\t"="" <<="" "last="" name:="" ";=""
cin.get(addin.lastname,="" 21,=""

cin.ignore(100,="" "first=""
cin.get(addin.firstname,="" "address="" line="" 1:=""
cin.get(addin.line1,="" 31,="" 2:=""
cin.get(addin.line2,="" 3:=""
cin.get(addin.line3,="" 4:=""
cin.get(addin.line4,="" "telephone="" number:=""
cin.get(addin.phone,="" 14,=""
system("cls");=""
}=""

void="" output_info(addresstype&="" addin,="" ofstream&="" outfile)=""
{=""
outfile<<addin.lastname="" "#"=""
<<addin.firstname=""
<<addin.line1=""
<<addin.line2=""
<<addin.line3=""
<<addin.line4=""
<<addin.phone="" endl;="" input_info(addresstype="" &addin)=""
ifstream="" infile;=""
infile.open(filename,="" ios::in);=""
if(infile.fail())=""
cout<<endl;=""
cout<<filename<<"="" could="" not="" be="" opened="" for="" writing="" into."<<endl;=""
cout<<"the="" file="" might="" corrupted."<<endl;=""
exit(1);=""

infile.get(addin.lastname,="" '#');=""
infile.ignore(1);=""
infile.get(addin.firstname,=""

infile="">> addin.line1;
infile.ignore(1);
infile >> addin.line2;
infile.ignore(1);
infile >> addin.line3;
infile.ignore(1);
infile >> addin.line3;
infile.ignore(1);
infile >> addin.phone;
infile.ignore(100, '\n');
}

void display_address_book(addresstype addin)
{

system("cls");
cout<<"All the entries are:"<
GeneralA window into a big world Pin
Bilal Naveed12-May-01 8:36
Bilal Naveed12-May-01 8:36 
GeneralRe: A window into a big world Pin
Christian Graus12-May-01 11:42
protectorChristian Graus12-May-01 11:42 
GeneralRe: A window into a big world Pin
Pros Chum12-May-01 12:20
Pros Chum12-May-01 12:20 
GeneralRe: A window into a big world Pin
Christian Graus12-May-01 13:29
protectorChristian Graus12-May-01 13:29 
GeneralRe: A window into a big world Pin
Ting16-May-01 11:16
Ting16-May-01 11:16 
GeneralRe: A window into a big world Pin
Christian Graus16-May-01 12:17
protectorChristian Graus16-May-01 12:17 
GeneralRe: A window into a big world Pin
David Fleming14-May-01 15:34
David Fleming14-May-01 15:34 
GeneralChallege Quistion: How to execute program from memory block Pin
12-May-01 7:02
suss12-May-01 7:02 
GeneralRe: Challege Quistion: How to execute program from memory block Pin
Gert Boddaert13-May-01 22:17
Gert Boddaert13-May-01 22:17 
GeneralAvoiding the windows error messageboxes to appear when WriteFile, CopyFile... and disk is removed Pin
Joan M12-May-01 0:44
professionalJoan M12-May-01 0:44 
GeneralRe: Avoiding the windows error messageboxes to appear when WriteFile, CopyFile... and disk is removed Pin
Tomasz Sowinski12-May-01 1:46
Tomasz Sowinski12-May-01 1:46 
Questionhow to convert a _variant_t to recordset in vc++? Pin
11-May-01 23:01
suss11-May-01 23:01 
AnswerRe: how to convert a _variant_t to recordset in vc++? Pin
chenzhu12-May-01 3:18
chenzhu12-May-01 3:18 
GeneralRe: how to convert a _variant_t to recordset in vc++? Pin
13-May-01 0:07
suss13-May-01 0:07 
Questionhow to PtinLine Function? Pin
11-May-01 17:00
suss11-May-01 17:00 
AnswerRe: how to PtinLine Function? Pin
Christian Graus12-May-01 2:55
protectorChristian Graus12-May-01 2:55 
GeneralglReadPixels() Help! Pin
11-May-01 16:52
suss11-May-01 16:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.