473,581 Members | 2,783 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

trouble reading the text file

bas
hey,

I am having a lot of trouble trying to get this program to work. It is
supposed to read integers from a file and place them into the
categories for inventory. The problem seems to be that the program is
only reading the first line of numbers from the text file and printing
them in ever category. Any help or suggestions woulud be great, I
swear i probably tried everything

#include <stdio.h>

int main(void)
{

int PartNo[5];
float Price[5];
int QOH[5];
int ReorderPt[5];
int MinOrder[5];
int x[4];
int i;
int y;
FILE *Fp1;

Fp1 = fopen("data.txt ", "r");

for(y=0;y<5;y++ )
{
for(i=0;i<4;i++ )
fscanf(Fp1,"%d" ,&x[i]");
PartNo[y] = ((x[0]*1000)+(x[1]*100)+(x[2]*10)+x[3]);
}

for(y=0;y<5;y++ )
{
for(i=0;i<4;i++ )
fscanf(Fp1, "%f", &x[i]);
Price[y] = ((x[0]*1000)+(x[1]*100)+(x[2]*10)+x[3])/100;
}

for(y=0;y<5;y++ )
{
for(i=0;i<4;i++ )
fscanf(Fp1, "%d", &x[i]);
QOH[y] = ((x[0]*1000)+(x[1]*100)+(x[2]*10)+x[3]);
}

for(y=0;y<5;y++ )
{
for(i=0;i<4;i++ )
fscanf(Fp1, "%f", &x[i]);
ReorderPt[y] = ((x[0]*1000)+(x[1]*100)+(x[2]*10)+x[3]);
}

for(y=0;y<5;y++ )
{
for(i=0;i<4;i++ )
fscanf(Fp1, "%f", &x[i]);
MinOrder[y] = ((x[0]*1000)+(x[1]*100)+(x[2]*10)+x[3]);
}

for(y=0;y<5;y++ )
{
if(QOH[y]<ReorderPt[y])
QOH[y] = QOH[y]+MinOrder[y];
}

printf("\n\b |-----------------------------------------------------------|");
printf("\n\b |Part Number --- Price --- Quantity on Hand --- Reorder
Point --- Minimum Order |");
printf("\n\b |-----------------------------------------------------------|");
printf("\n | %4d --- %2.2f --- %2d --- %2d |", PartNo[0], Price[0],
QOH[0], ReorderPt[0], MinOrder[0]);
printf("\n | %4d --- %2.2f --- %2d --- %2d |", PartNo[1], Price[1],
QOH[1], ReorderPt[1], MinOrder[1]);
printf("\n | %4d --- %2.2f --- %2d --- %2d |", PartNo[2], Price[2],
QOH[2], ReorderPt[2], MinOrder[2]);
printf("\n | %4d --- %2.2f --- %2d --- %2d |", PartNo[3], Price[3],
QOH[3], ReorderPt[3], MinOrder[3]);
printf("\n | %4d --- %2.2f --- %2d --- %2d |", PartNo[4], Price[4],
QOH[4], ReorderPt[4], MinOrder[4]);
printf("\n\b |-----------------------------------------------------------|");

return 0;
}
Nov 14 '05 #1
1 1448
Can you post a sample of the data file its using?

ba*****@cup.edu (bas) wrote in message news:<d3******* *************** ****@posting.go ogle.com>...
hey,

I am having a lot of trouble trying to get this program to work. It is
supposed to read integers from a file and place them into the
categories for inventory. The problem seems to be that the program is
only reading the first line of numbers from the text file and printing
them in ever category. Any help or suggestions woulud be great, I
swear i probably tried everything

Nov 14 '05 #2

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

Similar topics

4
1832
by: somaboy mx | last post by:
hi, I'm on winXPpro / apache 1.2 / php 4.4.x I'm experimenting with writing and reading from textfiles via php. I can create a file with fopen, write to it, but I'm having trouble reading from the file. here's a snippet:
7
4205
by: laclac01 | last post by:
So I am converting some matlab code to C++. I am stuck at one part of the code. The matlab code uses fread() to read in to a vector a file. It's a binary file. The vector is made up of floats, which in matlab is 32 bits. How do I get this binary file in to floats in c++? I try reading the file using the ifstream>>myFloat. But nothing ever...
22
2777
by: ext_u | last post by:
I'm trying to learn C from "The C Programming Language" (by K&R) and I am about halfway through the first chapter. I am using Miracle C as my text editor and compiler. Up until this point everything was working fine, but now the book has started into Line and Word counting programs. I am entering the programs into the text editor exactly...
2
2473
by: Sabin Finateanu | last post by:
Hi I'm having problem reading a file from my program and I think it's from a procedure I'm using but I don't see where I'm going wrong. Here is the code: public bool AllowUsage() { OperatingSystem os = Environment.OSVersion; AppDomain ad = Thread.GetDomain();
1
1658
by: Westbrook, Christopher L (WESTBCL04) | last post by:
I am having some trouble, and I can't figure out why. I'm trying to use the simple keylogger project from source forge, and then create a web interface to open the resulting files, so people from the outside can see the keys logged on a server. I've got the keylogger script working fine, and I have a script that reads and displays all the...
1
4938
by: khaleel.alyasini | last post by:
anyone could point me out where did i do wrong? it seems that i can't get back the original Lena image after the IDCT(inverse discrete cosine transform) process. the output raw image is nothing more than a grey colored canvas ... //Header files declarations #include <iostream.h> #include <fstream.h>
2
1364
by: Peter | last post by:
Hello, I am having alot of trouble reading in a date values from a text file which is exported from another application. My program is pretty basic, I read in values from a plain text file which had comma seperated values. I use the input statement to read the values from the file. eg. Input #1, name, dte1, tme1 The text file conists...
31
14451
by: tophandasa | last post by:
Hi all, I'm having a trouble reading a binary file as float values.I have to read the data in binary mode, then read every four bytes into a float variable. I have done my search, but i found out that the read and get functions do not accept float type. What should i do now? Can anybody help me please? Here is the code.. #include...
2
1232
by: tracethepath | last post by:
i hav written a program code for reading characters from a text file and convert upper case characters to lower case and vice-versa. Converted characters need to be saved in a new text file and this new text file shud be read and displayed on the monitor. wat i am doing is firstly i open two text files in the following manner: ifstream file1; ...
0
8156
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8310
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6563
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5681
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5366
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3809
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3832
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2307
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1144
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.