473,383 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Issue properly reading and handling input from file.

Hey guys just needed help with this code. When i do this code i actually needed the V wreck as the first invoice used, if you try the code you will know what im talking bout thanx guys

heres the code
Expand|Select|Wrap|Line Numbers
  1. // l3.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include<iostream> 
  6. #include <stdio.h> 
  7. #include <stdlib.h> 
  8.  
  9.  
  10.  
  11. using namespace std; 
  12.  
  13. /*
  14. int Sales(char *CustNoC) 
  15.   int i,j; 
  16.   float TUC=0.00; 
  17.   float UC; 
  18.   char CustNoS[3],ItemDesc[44], PartNo[7], 
  19.   UnitCost[10],Day[6],lastn[1]; 
  20.   char temp[1]; 
  21.   string fline; 
  22.  
  23.   FILE *infileS; 
  24.  
  25.   infileS = fopen("Sales.txt","r"); 
  26.   fscanf(infileS, "%s", &fline); 
  27.  
  28.  
  29.  
  30.   for(j=1;j<197;j++) 
  31.   { 
  32.        fscanf(infileS, "%c", &temp[0]); 
  33.        for(i=0;i<3;i++)fscanf(infileS,"%c",&CustNoS[i]); 
  34.  
  35.        for(i=0;i<44;i++)fscanf(infileS,"%c",&ItemDesc[i]); 
  36.        for(i=0;i<7;i++)fscanf(infileS,"%c",&PartNo[i]); 
  37.        for(i=0;i<10;i++)fscanf(infileS,"%c",&UnitCost[i]); 
  38.        for(i=0;i<6;i++)fscanf(infileS,"%c",&Day[i]); 
  39.        //fscanf(infileS,"%c",&lastn[0]); 
  40.        if(CustNoC[2] == CustNoS[2]) 
  41.        { 
  42.             for(i=0;i<44;i++)printf("%c",ItemDesc[i]); 
  43.             for(i=0;i<7;i++)printf("%c",PartNo[i]); 
  44.             printf("\t$"); 
  45.             for(i=0;i<10;i++)printf("%c",UnitCost[i]); 
  46.             for(i=0;i<6;i++)printf("%c",Day[i]); 
  47.             printf("/08/06\n"); 
  48.             UC =  (float) atof(UnitCost); 
  49.  
  50.             TUC = TUC + UC; 
  51.  
  52.        } 
  53.   } 
  54.   printf("\t\t\tTotal Invoice- $"); 
  55.   printf("%.2f\n",TUC); 
  56.   return 0; 
  57. */
  58.  
  59.  
  60.  
  61. int main() 
  62.   int i,j,k; 
  63.   float TUC=0.00; 
  64.   float UC;
  65.   char CustNoC[3], ComName[34],ABN[12], Street[35], 
  66.   Suburb[23],State[6],PostCode[8],Phone[12],lastn[1]; 
  67.   char temp[1]; 
  68.   char CustNoS[3],ItemDesc[44], PartNo[7], 
  69.   UnitCost[10],Day[6];//,lastn[1]; 
  70.   string fline; 
  71.  
  72.  
  73.   FILE *infileC; 
  74.   FILE *infileS;
  75.  
  76.   infileC = fopen("Customer.txt", "r"); 
  77.   fscanf(infileC, "%s", &fline); 
  78.   for(j=1;j<11;j++) 
  79.   { 
  80.  
  81.        fscanf(infileC, "%c", &temp[0]); 
  82.  
  83.        for(i=0;i<3;i++) fscanf(infileC,"%c",&CustNoC[i]); 
  84.        for(i=0;i<34;i++)fscanf(infileC,"%c",&ComName[i]); 
  85.        for(i=0;i<12;i++)fscanf(infileC,"%c",&ABN[i]); 
  86.        for(i=0;i<35;i++)fscanf(infileC,"%c",&Street[i]); 
  87.        for(i=0;i<23;i++)fscanf(infileC,"%c",&Suburb[i]); 
  88.        for(i=0;i<6;i++)fscanf(infileC,"%c",&State[i]); 
  89.        for(i=0;i<8;i++)fscanf(infileC,"%c",&PostCode[i]); 
  90.        for(i=0;i<12;i++)fscanf(infileC,"%c",&Phone[i]); 
  91.        printf("TOF ------ \n\n\nABN\t"); 
  92.        for(i=0;i<12;i++)printf("%c",ABN[i]); 
  93.        printf("\n"); 
  94.        for(i=0;i<34;i++)printf("%c",ComName[i]); 
  95.        printf("\n"); 
  96.        for(i=0;i<35;i++)printf("%c",Street[i]); 
  97.        printf("\n"); 
  98.        for(i=0;i<23;i++)printf("%c",Suburb[i]); 
  99.        for(i=0;i<6;i++)printf("%c",State[i]); 
  100.        for(i=0;i<8;i++)printf("%c",PostCode[i]); 
  101.        printf("\n\n"); 
  102.        for(i=0;i<12;i++)printf("%c",Phone[i]); 
  103.        printf("\n\n\n\n"); 
  104.  
  105.        //Sales(CustNoC); 
  106.        infileS = fopen("Sales.txt","r"); 
  107.        fscanf(infileS, "%s", &fline); 
  108.        for(k=1;k<197;k++) 
  109.        { 
  110.        fscanf(infileS, "%c", &temp[0]); 
  111.        for(i=0;i<3;i++)fscanf(infileS,"%c",&CustNoS[i]); 
  112.  
  113.        for(i=0;i<44;i++)fscanf(infileS,"%c",&ItemDesc[i]); 
  114.        for(i=0;i<7;i++)fscanf(infileS,"%c",&PartNo[i]); 
  115.        for(i=0;i<10;i++)fscanf(infileS,"%c",&UnitCost[i]); 
  116.        for(i=0;i<6;i++)fscanf(infileS,"%c",&Day[i]); 
  117.        //fscanf(infileS,"%c",&lastn[0]); 
  118.        if(CustNoC[2] == CustNoS[2]) 
  119.        { 
  120.             for(i=0;i<44;i++)printf("%c",ItemDesc[i]); 
  121.             for(i=0;i<7;i++)printf("%c",PartNo[i]); 
  122.             printf("\t$"); 
  123.             for(i=0;i<10;i++)printf("%c",UnitCost[i]); 
  124.             for(i=0;i<6;i++)printf("%c",Day[i]); 
  125.             printf("/08/06\n"); 
  126.             UC =  (float) atof(UnitCost); 
  127.  
  128.             TUC = TUC + UC; 
  129.        } 
  130.        } 
  131.        printf("\t\t\tTotal Invoice- $"); 
  132.        printf("%.2f\n",TUC); 
  133.  
  134.   } 
  135.   system("pause"); 
  136.   return 0; 
Customer.txt
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
1CaraCare Pty Ltd 1009733969 1 Myrtle Tree St Beech Bay NSW 97861400 567 789
2V-Wreck Pty Ltd 1000724240 25 Wentworth St Ironside NSW 92451310 345 123
3YardJunk Pty Ltd 1063888785 11 Lawson St Bellevue Hts NSW 91231305 678 678
4DaMaz Pty Ltd 1052869039 1 Granville St Dobble NSW 90011402 123 123
5Bounded Automobiles Pty Ltd 1086881881 150 Land Rd Blackfield NSW 93451406 456 456
6Basura Pty Ltd 1034505370 RMB 10 GoodGully Rd Blaxturn NSW 90101505 098 098
7Dismantle Pty Ltd 1053872755 22 Johnson Rd Bergalla NSW 80341600 238 792
8Heritage Auto Pty Ltd 1042733029 18 Meahan Ave Heams NSW 60221500 895 623
9Tracum Auto Spares Pty Ltd 1087378975 Unit 22/10 Industrial Drive Heams NSW 60221500 234 745
10Dudley's Autos Pty Ltd 1064654833 4 Marianne St Beech Bay NSW 97861400 322 788

Sales.txt
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxx
1Axle 1060997 435.6 30
4Oil Seal 1036470 132.8 5
3Front bearing 1023211 238.5 12
8Car Seat 1088587 345.8 8
9Rear Mirror 1073334 56.25 9
2LH Front Door 1068911 675.39 12
5Rocker Cover 1026992 120.65 7
10Cam Shaft 1047474 98.7 6
7Fuel Injector 1007347 25.8 28
7Hose 1031058 15.2 2
3Cooling Fan 1089358 68.4 9
8LH Front Shock Absorber 1043772 135.7 22
2Front Engine Mount 1027616 34.7 10
5Main bearing 1092951 34.78 6
Aug 27 '07 #1
1 1337
sicarie
4,677 Expert Mod 4TB
Sinanny-

Please have a look at the Posting Guidelines. We ask that you do things like put your code in code tags, ask specific questions, and use descriptive titles. This helps keep the forum clean an functioning.

Thanks,

sicarie
Aug 27 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Shane | last post by:
Hi, Thanks in advance for the help. I have been to many websites and tried several solutions to my problem, but have fixed part of it. It's time to come humbly to the newsgroups for help :-) ...
4
by: John Fereira | last post by:
So, one of the limitations of multipart-form handling is that when an <input type="file" ..> tag is used it will bring up a window which allows a user to select a file for upload but won't allow...
8
by: dbuser | last post by:
Hi, I need help on a problem, as described below. I am reading a file "input.txt"which has data like this: abc def gh izk lmnopq rst uvwxyz I am using fstream object to read the file and...
1
by: Magnus | last post by:
allrite folks, got some questions here... 1) LAY-OUT OF REPORTS How is it possible to fundamentaly change the lay-out/form of a report in access? I dont really know it that "difficult", but...
28
by: Colin JN Breame | last post by:
Hi, Fairly new to C. What is the best way to read a line (\n terminated) from a file? Ive looked at fscanf but was not sure which format specifier to use. (%s perhaps). Thanks Colin
3
by: gmtonyhoyt | last post by:
Okay, this one's a tough one for me to explain so this might take a few e-mails to get the idea across. Here's what I got though. I have this application running on a Sun/Solaris machine,...
12
by: dough | last post by:
I want to read in lines from a file and then seperate the words so i can do a process on each of the words. Say the text file "readme.txt" contains the following: In the face of criticism from...
13
by: souissipro | last post by:
Hi, I have written a C program that does some of the functionalities mentionned in my previous topic posted some days ago. This shell should: 1- execute input commands from standard input,...
4
by: zr | last post by:
Hi, i need to read a text file which contains a list of items, all of type ItemType, separated by whitespace and newlines. For each line, there will be a vector<ItemTypeobject that will store...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.