-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQN005.c
42 lines (36 loc) · 794 Bytes
/
QN005.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
/**
* Write a program to read all numbers from the input file "values.dat" and
* store only even numbers in an output file named as "result.res".
*/
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *f1, *f2;
int num, n, i;
printf("Enter the size of number:\n");
scanf("%d", &n);
printf("Enter numbers:\n");
f1 = fopen("values.dat", "w");
for (i = 0; i < n; i++)
{
scanf("%d", &num);
putw(num, f1);
}
fclose(f1);
f1 = fopen("values.dat", "r");
f2 = fopen("result.res", "w");
while ((num = getw(f1)) != EOF)
{
if (num % 2 == 0)
putw(num, f2);
}
fclose(f1);
fclose(f2);
f2 = fopen("result.res", "r");
printf("Contents of Even file:\n");
while ((num = getw(f2)) != EOF)
printf("%d\n", num);
fclose(f2);
return 0;
}