forked from sarjus/C-Programing-KTU
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopyonefiletoanother.c
43 lines (33 loc) · 1.17 KB
/
copyonefiletoanother.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/******************************************************
* File : checksymmetricmatrix.c
* Description : Write a program in C to copy the contents of one file into another.
* Author : Sarju S
* Version : 1.0
* Date : 21/05/2021
* ***************************************************/
#include <stdio.h>
#include <stdlib.h>
int main() {
FILE *sourceFile, *destFile;
char sourceFileName[100], destFileName[100];
char ch;
// Ask user for the name of the source file
printf("Enter the name of the source file: ");
scanf("%s", sourceFileName);
// Open the source file in read mode
sourceFile = fopen(sourceFileName, "r");
// Ask user for the name of the destination file
printf("Enter the name of the destination file: ");
scanf("%s", destFileName);
// Open the destination file in write mode
destFile = fopen(destFileName, "w");
// Copy contents from source file to destination file
while ((ch = fgetc(sourceFile)) != EOF) {
fputc(ch, destFile);
}
printf("File copied successfully.\n");
// Close the files
fclose(sourceFile);
fclose(destFile);
return 0;
}