#include <stdio.h>
#include <string.h>
struct sale
{
int week;
int units;
int price;
char name[30];
};
File *inFile;
File *outFile;
int main(int argc, char *argv[])
{
int week = 0;
int units = 0;
int price = 0;
char name[30];
int count = 13;
int i = 0;
struct sale weeklySale[13];
int total = 0;
//int total_Sale[13];
for (i = 0; i < 13; i++)
{
scanf("%i %i %i %s", &weeklySale[i].week, &weeklySale[i].units, &weeklySale[i].price, weeklySale[i].name);
if(weeklySale[i].week > 13)
{
break;
}
}
inFile = fopen(argv["data.txt"], "r");
outFile = fopen(argv["data.txt"], "w");
fprintf(outFile, "%i %i %i %s", &weeklySale[i].week, &weeklySale[i].units, &weeklySale[i].price, weeklySale[i].name);
fscanf(inFile, "%i %i %i", &week, &units, &price);
int total = &units * &price;
printf("Week Total Sales \n");
printf("%i %i", week, total);
return 0;
}
this is the code i have so far, i want to save the variables from the struct (weeklySale) into a file (data.txt), then read them back from the same file, perform a calculation with the data that i retrieved, and then display them to the screen.
the problem is in the two lines just above the int main() function and there is also a problem with the code in the main part of the program from the "inFile" command all the way to the last "printf" statement.
can you please check it out and let me know what you think might be causing the problem, it is doing my head in
This post has been edited by pro-grammer: 18 December 2008 - 09:34 AM

New Topic/Question
Reply




MultiQuote






|