rendered paste bodyALTERED CODE - ORIGINAL BELOW
#include <stdio.h>
int copyfile(char *source,char *dest) {
FILE *sourceFile;
FILE *destinationFile;
char *buffer;
int n;
printf(source);
printf("\n");
printf(dest);
sourceFile = fopen(source, "r");
destinationFile = fopen(dest, "w");
if(sourceFile==NULL) {
printf("Error: can't access file.c.\n");
return 1;
}
else if(destinationFile==NULL) {
printf("Error: can't create file for writing.\n");
return 1;
}
else {
n = fread(buffer, 1, 1000, sourceFile); /* grab all the text */
fwrite(buffer, 1, n, destinationFile); /* put it in file2.c */
fclose(sourceFile);
fclose(destinationFile);
destinationFile = fopen(dest, "r");
n = fread(buffer, 1, 1000, destinationFile); /* read file2.c */
printf("%s", buffer); /* display it all */
fclose(destinationFile);
return 0;
}
}
int main(void) {
copyfile("file.c","file2.c");
}
ORIGINAL
#include <stdio.h>
int main() {
FILE *sourceFile;
FILE *destinationFile;
char *buffer;
int n;
sourceFile = fopen("file.c", "r");
destinationFile = fopen("file2.c", "w");
if(sourceFile==NULL) {
printf("Error: can't access file.c.\n");
return 1;
}
else if(destinationFile==NULL) {
printf("Error: can't create file for writing.\n");
return 1;
}
else {
n = fread(buffer, 1, 1000, sourceFile); /* grab all the text */
fwrite(buffer, 1, n, destinationFile); /* put it in file2.c */
fclose(sourceFile);
fclose(destinationFile);
destinationFile = fopen("file2.c", "r");
n = fread(buffer, 1, 1000, destinationFile); /* read file2.c */
printf("%s", buffer); /* display it all */
fclose(destinationFile);
return 0;
}
}