Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

***** C PROGRAMMING (not C++) ****** Need help to fix this C code, or if it is fine then help with getting it to run

***** C PROGRAMMING (not C++) ****** Need help to fix this C code, or if it is fine then help with getting it to run and show/read/edit the file created

#include #include

int main() {

int i, a, b, sum = 0; do { printf(" Enter integers a, b:"); scanf("%d %d",&a,&b); printf("Sum: a + b = %d ",a+b); printf("(0 to quit)."); scanf("%d",&i); }while(i != 0);

FILE *fptr1, *fptr2; char filename[100], c;

printf("Enter the filename to open for reading "); scanf("%s", filename); // Open one file for reading fptr1 = fopen(filename, "r"); if (fptr1 == NULL) { printf("Cannot open file %s ", filename); exit(0); }

printf("Enter the filename to open for writing "); scanf("%s", filename);

// Open another file for writing fptr2 = fopen(filename, "w"); if (fptr2 == NULL) { printf("Cannot open file %s ", filename); exit(0); }

// Read contents from file c = fgetc(fptr1); while (c != EOF) { fputc(c+2, fptr2); c = fgetc(fptr1); }

printf(" Contents copied to %s", filename);

fclose(fptr1); fclose(fptr2);

return 0; } >>>>>>>>>>>>>>>>>>>> I am able to enter the integers but cannot make a file called "test" and "out" to read and write please help make this code error free, thank you!

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 Concepts

Authors: David M Kroenke, David J Auer

6th Edition

0132742926, 978-0132742924

More Books

Students also viewed these Databases questions

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago