Apr 15, 2013

C program to find the size of a text file without traversing it character by character


#include<stdio.h>
#include<conio.h>
#include<dos.h>
void main()
{
struct entry
{
char fname[8];
char ext[3];
char unusual[17];
long int size;
};
struct entry e[16];
int i,j,c;
char yname[8];
char ch=1,len,len1;
clrscr();
absread(0,1,5,e);
for(i=0;i<16;i++)
printf("%s %s %d\n",e[i].fname,e[i].ext,e[i].size);
printf("enter the filename whose size is to be found");
scanf("%s",&yname);
len1=len=strlen(yname);
i=0;
while(i<16)
{
while(len--!=0)
{
if(e[i].fname[len]==yname[len])
ch=0;
else
{
ch=1;
break;
}
}
if(ch==0&&len==-1)
break;
len=len1;
i++;
}
if(ch==0)
{
printf("%s",e[i].fname);
printf("\t%ld bytes",e[i].size);
}
else
printf("h");
getch();
}

0 comments:

Post a Comment