In: Computer Science
The C++ program below simply copies the contents of one file to another file using standard in and standard out. Do a line-by-line conversion of the complete program into a closely equivalent C program that produces the same output given the same input. Note that the underscores are used solely to force indentation in Canvas. #include using namespace std; int main(void) { char symbol; cin.get(symbol); while (!cin.eof()) ___ { ___ cout.put(symbol); ___ cin.get(symbol); ___ } return 0; }
#include <stdio.h> //header file
#include <stdlib.h>
int main()
{
FILE *f1, *f2;
FILE *f1, *f2;
char file[50],symbol;
f1 = fopen("abc.txt", "r"); // open to read file abc.txt.
if (f1 == NULL)
{
printf("Cannot open file %s \n", file);
exit(0);
}
printf("Enter the file name (new file) \n");
scanf("%s", file);
f2 = fopen(file, "w"); // Open new file for writing
if (f2 == NULL)
{
printf("Cannot open file %s \n", file);
exit(0);
}
symbol = fgetc(f1); //Obtain single character at time from read
file.
while (symbol != EOF) // till end of file
{
fputc(symbol, f2); //write character to new file
symbol = fgetc(f1);
}
printf("\nCopied to file %s", file);
fclose(f1); //close read file
fclose(f2); // close write file
return 0;
}