473,507 Members | 2,504 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 1438
Can you post a sample of the data file its using?

ba*****@cup.edu (bas) wrote in message news:<d3**************************@posting.google. 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
1823
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...
7
4203
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,...
22
2766
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...
2
2464
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() { ...
1
1632
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...
1
4928
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...
2
1356
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...
31
14422
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...
2
1221
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...
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
7110
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7372
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...
1
7030
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7482
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
5041
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...
1
758
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.