-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathQ29.c
More file actions
26 lines (26 loc) · 684 Bytes
/
Q29.c
File metadata and controls
26 lines (26 loc) · 684 Bytes
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
/* Program: 29
Write a C program to copy the contents of one file into another file.
*/
#include <stdio.h>
void main()
{
FILE *fp1 = NULL, *fp2 = NULL;
char ch;
fp1 = fopen("rajkishor.txt", "r");
if (fp1 == NULL)
{
printf("rajkishor.txt file is not open");
exit(1);
}
fp2 = fopen("raj.txt", "w");
if (fp2 == NULL)
{
printf("raj.txt file is not open");
exit(1);
}
while ((ch = getc(fp1)) != EOF)
fputc(ch, fp2);
printf("file successfully copied");
fclose(fp1);
fclose(fp2);
}