Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Marketing The New Profit Frontier

Authors: Ed Burnett

1st Edition

0964535629, 978-0964535626

More Books

Students also viewed these Databases questions