C Programming help!

jondl

Senior member
Aug 16, 2005
561
0
0
Thanks everyone for all the comments and help. The program works like a charm now.
 

itachi

Senior member
Aug 17, 2004
390
0
0
u're forgetting about the string that starts at the beginning of the line. when u try and read a number, but it finds a string at that position.. it won't discard the string, it'll just return 0 or -1.
the easiest thing to do would be read 2 strings and 4 ints - fscanf(fpNum, "%s%s%d%d%d%d", ...).
 

jondl

Senior member
Aug 16, 2005
561
0
0
Here are the instructions given to me.. I am not expecting ANYONE to write the program for me. I just need some hints and i'll try to update as much as possible.

The following table shows the total sales for salespeople of the ABC
Manufacturing Company.

Salesperson Week 1 Week 2 Week 3 Week 4
=============== ====== ====== ====== ======
Nguyen, Michael 25 30 45 20
Johnson, Mary 32 30 33 29
Nagasake, David 15 17 21 20
...

The price of the product being sold is $1985.95 Define it as a memory
constant.

Write a program that permits the input of the data, up to 25 salespersons,
and prints both a replica of the original table and a table showing the
dollar value of sales for each individual during each week along with his
or her total sales. Also print the total sales, the lowest and the highest
value for each week, and the total sales for the company.

Input : Read data from a text file. A salesperson's name consists of
20 characters. The first number in the input file represents
the number of salespersons. The input file format is as follows:

3
Nguyen, Michael 25 30 45 20
Johnson, Mary 32 30 33 29
Nagasake, David 15 17 21 20

Output : See SAMPLE_OUTPUT.TXT
Write the output to another text file.

Write a beginning message, an ending message,
and any other messages such as
" *** Error opening/closing files *** ",
" *** Warning: data file is to large *** ", or
" *** The output is in SALESRES.TXT *** "
to screen.

Data : Run your program once using the data file SALES.TXT

Note : DO NOT USE STRINGS! Read all names one character at a time.
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Here's code you apparently can't use because you suck at explaining what you're supposed to do. I wrote it before I saw your second post.
 

jondl

Senior member
Aug 16, 2005
561
0
0
OK, I've managed to print out the whole txt file but am still clueless on how to separate the names from the numbers so that i can put them into their respective arrays.

Heres the code i have so far..
 

Dark4ng3l

Diamond Member
Sep 17, 2000
5,061
1
0
Look I am pretty sure you should read it this way. You know that the stuff will be written in that order in the file. Read the original number(amount of people) you use that to know how many times you need to run your loop. Then you will read and store a single character at a time. The way you separate numbers from letters is that you know the order the data is in(name, name number number number). What you need to do is "read untill (,)" store that then go to the next "word" discarding any , or spaces. Then you store everything individually wherever you want it.