How do I get the C program to scan the information in a .txt file and arrange it in a new .txt file? I have
How do I get the C program to scan the information in a .txt file and arrange it in a new .txt file? I have been trying to do this with fprintf and fscanf but I haven't figured out how to arrange it correctly.
#include
#include
#define ITEMS 51
int i;
int s;
int main(void)
{
FILE* costs = fopen("Costs.txt", "r");
FILE* total_sales = fopen("Total_sales.txt", "w");
int totalSalesArray[2][50]= {{},{}};
for (int i = 0; i < 2; i++) //outer loop
{
for (int s = 0; s < 50; s++) // inner loop
{
printf("%d", totalSalesArray[i][s]);
}
printf(" ");
}
fprintf(total_sales, "%d", totalSalesArray[i][s]); //write two lines
fclose(total_sales);
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started