Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 09-11-2005, 09:58 AM   #1 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
Why?

How come when you start the program the name, house, class get read from a file but when the print opion has been chosen the print function runs, but upon completion the name disappears?

Code:
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
#include <conio.h>
#include <ctype.h>
#include <dos.h>

void print (void);

int records;
char name[20];
char house;
int set;

int main (void)
{
  int ln;
  char choice;
  ifstream data (".\\Students.txt");
  data >> name;
  data >> house;
  data >> set;
  if (data == 0)
  {
  cout << "Error";
  }
  else
  {
    do
    {
  gotoxy(8,8);
  cout << (char)218 << setw(21) << setfill((char)196) << (char)191 << endl;
  gotoxy(7,9);
  cout << (char)218 << (char)217 << setw(21) << setfill(' ') << (char)192 << setw(45) << setfill((char)196) << (char)191 << endl;
  ln = 10;
  do
  {
    gotoxy(7,ln);
    cout << (char)179 << setw(67) << setfill(' ') << (char)179 << endl;
    ln++;
  } while (ln != 15);
  gotoxy(7,15);
  cout << (char)192 << setw(67) << setfill((char)196) << (char)217 << endl;
  gotoxy(10,9);
  cout << "STUDENT RECORDS...";
  gotoxy(7,17);
  cout << (char)218 << setw(67) << setfill((char)196) << (char)191 << endl;
  ln = 18;
  do
  {
    gotoxy(7,ln);
    cout << (char)179 << setw(67) << setfill(' ') << (char)179 << endl;
    ln++;
  } while (ln != 22);
  gotoxy(7,22);
  cout << (char)192 << setw(67) << setfill((char)196) << (char)217 << endl;
  gotoxy(9,19);
  cout << "Press 'A' to add new record, 'P' to print records, 'N' to view";
  gotoxy(9,20);
  cout << "next record or 'R' to return to main menu.";
  do
  {
  gotoxy(9,11);
  cout << "Name: " << name;
  gotoxy(9,12);
  cout << "House: " << house;
  gotoxy(9,13);
  cout << "Class: " << set;
  data >> name;
  data >> house;
  data >> set;
  gotoxy(60,20);
  cin >> choice;
  choice = toupper (choice);
  } while (choice == 'N');
  data.close();
  switch (choice)
  {
    case 'A':
             break;
    case 'P': print();
             break;
    case 'R':
             break;
    default: cout << "Error";
  }
  } while (choice != 'R');
  }

  return 0;
}

void print (void)
{
  ifstream data (".\\Students.txt");
  ofstream printer ("LPT1");
  records = 0;
  clrscr();
  gotoxy(31,13);
  cout << "Printing, Students.txt" << endl;
  gotoxy(22,16);
  cout << setw(40) << setfill('=') << endl;
  gotoxy(22,18);
  cout << setw(40) << setfill('=') << endl;
  delay(1000);
  gotoxy(23,17);
  cout << setw(38) << setfill('>') << endl;
  delay(1000);
  printer << "data.txt" << endl;
  printer << "-----------------------------------------------------------------------------" << endl;
  printer << "                                                                       Page 1" << endl;
  do
  {
    data >> name;
    data >> house;
    data >> set;
    printer << name << " ";
    printer << house << " ";
    printer << set << endl;
    records++;
  } while (!data.eof());
  printer << "-----------------------------------------------------------------------------" << endl;
  printer << " Records in file: " << records << endl;
  printer << "-----------------------------------------------------------------------------" << endl;
  printer << "\f";
  printer.close();
  data.close();
}
__________________
Many Thanks, in advance!

Salchester.
The Future Is Here - Are You Ready?
Salchester is offline   Reply With Quote
Old 09-11-2005, 06:55 PM   #2 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
O.K. this is the ISO STANDARD C++ forum. I don't want to see conio's and dos.h's anymore. Retype your program and remove the things that are not needed for your question.

Also, look up on this forum why you should change
<iostream.h>
<fstream.h>
<iomanip.h>
<ctype.h>
into
<iostream>
<fstream>
<iomanip>
<cctype>

This is all part of the ISO standard.
Also, when using char* (or char[]), use std::string from the <string> header instead unless there is an URGENT reason not to do so. Ok, first remove the non-iso items then post so we can talk further. Also add some comments so peeps can read what you're up to.
__________________
Valmont is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 09:22 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting