Files 453
printf ("F ile: %s Bytes: % d
",name [I]jc[l]);
t=t+x[l];
for (l= t;l>=l;l~ )
I
for (k=0;k<3;k++)
I
if(l= = x [k ])
printf ("% s are the largest file.",name[k]);
exit(l);
I
I
OUTPUT:
File:l.txt Bytes: 16
File: 2.txt Bytes:20
File : 3.txt Bytes : 25
3.txt are the largest file.
Explanation In the above program an array of file pointer and a separate file pointer f p are declared.
The two-dimensional character array is used for storing file names. Using file pointer array in the
f o r loop three files are opened in read mode. Each element of file pointer array points to the
corresponding elements of character array i.e. file names.
The f g e t c () function in the w h ile loop reads the contents of each file one by one. The numbers of
characters are also written to integer array in the same loop. At the end the values stored in integer
array are compared with one another and the file containing the largest number of bytes is detected.
The name of the largest file is displayed.
13.34 Write a program to copy up to 100 characters from a file to an array. Then copy the
contents of an array to another file.
# include <stdio.h>
# include <conio.h>
# include <process.h>
# define SIZE 100
void mainO
{
PILE * f , *f2;
static char c,ch[SIZE];