File I/O Stream


 
Thread Tools Search this Thread
Top Forums Programming File I/O Stream
# 1  
Old 05-05-2004
File I/O Stream

Hi All,

I am trying to read data from two files and then compare them and only print the records on the screen that have a same ID.i.e TAGNO =CUSTOMERNO
For Eg
My Input Files are (a) Transaction (b) Customer detail
The data in file a is like:
TagNo Date Time Station
4092191 03/08/04 23:49:08 A
4749038 05/04/04 14:16:35 B
4092191 04/13/04 23:42:08 C
4092191 04/13/04 23:47:18 D
3873242 05/16/04 02:40:59 B

Data in File B
CustomerNo Initila Surname Street Suburb State Postcode
4092191 T Menon Evan Penrith NSW 2750
3873242 R Merritt Bent Mosman NSW 2090

Additional Criteria is , if the Grade is A the charges 2.20, B- 2.80, C-3.30 & D -3.80.

The expected output is :
Customer No:
Customer Name:
Address:
details of the transactions:
=======================
Customer No Date Time Grade Charges

Below is the code I am trying:

#include <stdlib.h>
#include <fstream.h>
#include <cstring.h>
#include <stdlib.h>
#include <iomanip.h>
void main()
{
string Dt,Tm;
float Charges;
string TagNumber, CustomerNo;
char Station;
string Intial,Surname,StreetNo,StreetName;
//char Intial[2],Surname[10],StreetNo[3],StreetName[20];
char StreetType[20],Surburban[20],State[20],Postcode[5];
float calc_charges( string Station );


//open the files
ifstream InStream("a:\trans.txt",ios::in), InStream1("a:\customer.txt",ios::in);

// check for Instream File, if the file doesn't exist, print error message
if (InStream.fail()) // check for success
{
cerr << "\n Unable to open 'data.txt'!\n";
exit (-1); //
} // end if

if (InStream1.fail()) // check for success
{
cerr << "\n Unable to open 'data.txt'!\n";
exit (-1); //
} // end if


while (!InStream.eof()) // while not end-of-file:
{

InStream >> TagNumber>>Dt>>Tm>>Station;
Charges = calc_charges( Station );

} //while(!input.eof());

//open the customer detail file

// ifstream InStream1("a:\customer.txt",ios::in);

// if the file doesn't exist, print error message
if (InStream1.fail()) // check for success
{
cerr << "\n Unable to open 'customer.txt'!\n";
exit (-1); //
} // end if


while (!InStream1.eof()) // while not end-of-file:
{

InStream1 >> CustomerNo>>Intial >> Surname>> StreetNo>> StreetName
>> StreetType >> Surburban>> State>> Postcode;


cout << "\n Customer Name : " << Intial <<" " << Surname <<endl;
cout << " Address : " <<StreetNo << " "<<StreetName << " " <<StreetType<<endl;
cout << Surburban << " " << State << " " << Postcode <<endl;
cout << " Customer Number : " << CustomerNo <<endl;
cout <<endl;
cout << CustomerNo << "|" << Dt << "|" << Tm << "|" <<Station
<< " " << setw(4) << setiosflags(ios::fixed) << setprecision(2)
<< Charges << endl;
}
}


// function definition
float calc_charges( string Station )
{
float the_Charge;
if (Station == 'A')
the_Charge = 2.20;
else if (Station == 'B')
the_Charge = 2.80;
else if (Station == 'C')
the_Charge = 3.30;
else if (Station == 'D')
the_Charge = 3.80;

return the_Charge;
}

==================
The output that it gives is not correct.

Can someone Please help me out.

Thanks
rooh
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

Play STRG - E-Viewer Recorded Stream file

I have got a .strg file, which I cannot open. I tried NMS Player from Novus, but It can't handle STRG files. How can I play these recordings? (1 Reply)
Discussion started by: kovacsdev
1 Replies

2. Shell Programming and Scripting

Wget for downloading a public file (stream) as mp4

I need a hint for using wget for getting a free content from a TV station that is streaming its material for a while until it appears on any video platform, that means no use of illegal methods, because it is on air, recently published and available. But reading the manual for wget I tried the... (5 Replies)
Discussion started by: 1in10
5 Replies

3. Shell Programming and Scripting

Creating a file from input stream

Hi, Need some help with creating a file from input steam. Meaning from following command myfunc should be able to store the input stream to a file. echo a b c | myfunc The file thus created should have - a b c Here's what I've tried in myfunc() but didn't help - myfunc() { cat... (3 Replies)
Discussion started by: nexional
3 Replies

4. AIX

When AIX audit start, How to set the /audit/stream.out file size ?

Dear All When I start the AIX(6100-06)audit subsystem. the log will save in /audit/stream.out (or /audit/trail), but in default when /audit/stream.out to grow up to 150MB. It will replace the original /audit/stream.out (or /audit/trail). Then the /audit/stream.out become empty and... (2 Replies)
Discussion started by: nnnnnnine
2 Replies

5. UNIX for Dummies Questions & Answers

What is an (application/octet-stream) file?

I'm trying to learn as much about GRUB as I can and it's stages are stored in these types of files. Any info or search terms is appreciated!:wall: (5 Replies)
Discussion started by: theKbStockpiler
5 Replies

6. Shell Programming and Scripting

Removing all lines prior to the last pattern in a file/stream

Hi all, I didn't find anything that specifically answers this after searching for a bit, so please forgive me if this has been covered before. I'm looking to delete all lines prior to the last occurrence of a string in a file or stream from within a shell script (bash.) A bit of... (4 Replies)
Discussion started by: LivinFree
4 Replies

7. Shell Programming and Scripting

Stream all log files into one file

Here is what I have. 1 main program and it calls several child programs. Each child has its own log file. I want all child logs also to be appended to the main.log so that I have a single log file. I also need individual child logfiles in tact for debug purposes. Need to be able to tail one log... (4 Replies)
Discussion started by: myjunk1
4 Replies

8. Shell Programming and Scripting

[Video stream] network stream recording with mplayer

Hi I used this command: mplayer http://host/axis-cgi/mjpg/video.cgi -user root -passwd root \ -cache 1024 -fps 25.0 -nosound -vc ffh264 \ -demuxer 3 -dumpstream -dumpfile output.avi It's ok but... Video Playing is very fast! Why? Is it a synch problem? What parameter I have to use for... (1 Reply)
Discussion started by: takeo.kikuta
1 Replies

9. Ubuntu

Stream video

Hello, I have Ubuntu 64 bit 9.04 install dual boot I can't see stream videos through Opera I couldnt see it in Firefox did this: "sudo apt-get install ubuntu-restricted-extras flashplugin-nonfree" Now I can see it in firefox but not in Opera Should not care and just use just Firefox. thanks (0 Replies)
Discussion started by: Pitroadrush
0 Replies

10. Programming

open file stream problem

I have faced a problem that I use 2 file streams in a function and try to fopen() both files. Then I can't get the file descriptor. But if I just use 1 file stream and 1 fopen(), then i can get the file descriptor. Does anybody know why this happens? Thanks in advance. ... (2 Replies)
Discussion started by: ivancheung
2 Replies
Login or Register to Ask a Question