473,507 Members | 2,416 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C++ Help with displaying code from file

Hi,

I'm trying to display customer details on screen from a file using
functions.

The details are written to the file first then I display them on screen
after I search for the file.

My problem is this:

I'm trying to display the details individually using this function for
void display();

All the other code is written I just need to get this function to run.

===============================================

void display()
{

char filename[15];
char in_char,ans;
int line;

do
{
clrscr();
cout<<"\nTo Display Contractor Details on the Screen";
cout<<"\nType the file name you want to see";
cout<<"\n\nEG. F:YOUR_FILE_NAME.txt :";
cin>>filename;

infile.open(filename, ios::in);
if(!infile)
{
clrscr();
cout<<"\n\n****That file does not exist****\n";
cout<<"Type F:\ and then up to eight letters for the file name,"
<<" then a dot and then three characters for the file type";
cout<<"\n\nEXAMPLE F:\THISFILE.TXT";
cout<<"\n\nDo you want to QUIT (Y/N)";
cin>>ans;
ans=toupper(ans);
}

}while((!infile)&&(ans!='Y'));

while(infile.get(in_char))
if (line>20)
{

cout<<(in_char);
cout<<"\n\nThat is the screen full...\n"
<<"\npress any key to clear it and continue...";
getch();
clrscr();

}
infile.close();

return;
}

===============================================

When I run this code it displays each character one at a time and not
the details.

The details are about 10 lines long and I need the program to say
"screen full" so that when I click continue the next set of details
comes up...

I been looking and trying everything for 3 hours now and I must be
missing something... can anyone point me in the right direction.

Thanks for your time.

Oct 25 '05 #1
1 1328
no*****@gmail.com wrote:
Hi,

I'm trying to display customer details on screen from a file using
functions.

The details are written to the file first then I display them on screen
after I search for the file.

My problem is this:

I'm trying to display the details individually using this function for
void display();

All the other code is written I just need to get this function to run.

===============================================

void display()
{

char filename[15];
char in_char,ans;
int line;

do
{
clrscr();
cout<<"\nTo Display Contractor Details on the Screen";
cout<<"\nType the file name you want to see";
cout<<"\n\nEG. F:YOUR_FILE_NAME.txt :";
cin>>filename;

infile.open(filename, ios::in);
if(!infile)
{
clrscr();
cout<<"\n\n****That file does not exist****\n";
cout<<"Type F:\ and then up to eight letters for the file name,"
<<" then a dot and then three characters for the file type";
cout<<"\n\nEXAMPLE F:\THISFILE.TXT";
cout<<"\n\nDo you want to QUIT (Y/N)";
cin>>ans;
ans=toupper(ans);
}

}while((!infile)&&(ans!='Y'));

while(infile.get(in_char))
if (line>20)
{

cout<<(in_char);
cout<<"\n\nThat is the screen full...\n"
<<"\npress any key to clear it and continue...";
getch();
clrscr();

}
infile.close();

return;
}

===============================================

When I run this code it displays each character one at a time and not
the details.

The details are about 10 lines long and I need the program to say
"screen full" so that when I click continue the next set of details
comes up...

I been looking and trying everything for 3 hours now and I must be
missing something... can anyone point me in the right direction.

Thanks for your time.


Look at your variable line. Where do you give it a value? Answer,
nowhere. How does you problem say you need to read the file? Answer,
line by line. How do you read the file? Answer, character by character.

I don't know what you mean when you say that you must be missing
something, the problem is that your code bears no relation to the
problem you are trying to solve.

Here's a better way

int line_count = 0;
while (read a line from file)
{
display line;
++line_count;
if (line_count%20 == 0)
display 'press any key to continue';
}

Something like that anyway, you can fill in the gaps.

john
Oct 25 '05 #2

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

Similar topics

17
6515
by: Axel | last post by:
Hiho, here my Newbie question (Win32 GUI): I'm reading a file in binary mode to a char* named buffer. I used malloc(filesize) to make the needed space avaiable. The filedata in the buffer...
2
2831
by: Joe Price | last post by:
Hi chaps I've got an XML file, within that file i've embedded html code using the <!]> tag I'm displaying that xml file through a browser using an xsl style sheet. However it is displaying...
0
1560
by: Wynter | last post by:
RE: from Displaying a Document using the ASPNET user account to the Client Browser discussion (3/2/2004 Buddy Thanks for helping me on getting the document to display. But now I am left with a...
1
1949
by: Mark ??;-\) | last post by:
I would like to display a listing of files on a web page as follows: If there is only one file: display the section name and then display the current file. If there is more than one file (for...
3
5457
by: Kidus Yared | last post by:
I am having a problem displaying Unicode characters on my Forms labels and buttons. After coding Button1.Text = unicode; where the unicode is a Unicode character or string (‘\u1234’ or...
0
1709
by: Fronky | last post by:
Hope someone can help. I am still learning, so no laughing please. I am displaying records from a database using Response.Write(""); instead of the usual datagrid method. I am doing it this way...
1
1326
by: asad | last post by:
hello how ru all, i have some problem in displaying xml file in asp.net, i successfully create an xml file but when want to display it through ASP.NET code it throwing following error. ...
12
2636
by: Patxi | last post by:
This is the first time I try to use cookies, and despite of reading some tutotials, I'm have real trouble to make it work correctly. My cookie reading code is in Master Page. When I click on a...
5
2355
by: dav3 | last post by:
I am by no means an ultra slick programmer and my problem solving skills.. well they leave much to be desired. That being said I have been working on the following problem for the past few days and...
2
2170
by: peteinglastonbury | last post by:
I'd be most grateful if someone would help me. I hope I'm in the right forum (apologies if not) - I'm not sure whether my problem is CGI or Javascript related. I found a script called...
0
7223
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
7319
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,...
0
7376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7485
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5623
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,...
1
5042
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...
0
4702
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...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
760
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.