The files may vary in size, but they should have complete sets of information. For example, keep to your current code and say, remove the last price from the file. You will probably find that...
Type: Posts; User: laserlight
The files may vary in size, but they should have complete sets of information. For example, keep to your current code and say, remove the last price from the file. You will probably find that...
Checking against the number of format specifiers is usually better in case the input is not well formed (though your results will arguably still be bogus). Notice also that I used %29s instead of...
In that case, that loop really should just be this:
while (fscanf(input, "%i%29s%i%i", &info.week, info.name, &info.units, &info.price) == 4)
{
week[info.week] += info.units * info.price;
...
On second thought, it should be more like:
while (fscanf(input, "%i%29s%i%i", &info.week, info.name, &info.units, &info.price) == 4)
{
week[info.week] = info.total = info.units * info.price;...
Try:
while (fscanf(input, "%i%29s%i%i", &info.week, info.name, &info.units, &info.price) == 4)
{
week[info.week] += info.units * info.price;
info.total = week[info.week];
if...
Eh, this looks wrong:
input = fopen(argv[1], "r") ;
output = fopen(argv[2], "w") ;
if(( fopen(argv[1], "r")) == NULL)
{
printf("Sorry, this file cannot be opened.\n") ;
...
Yes, though if it is too long, show the smallest and simplest compilable program that demonstrates the problem.