Write an ALP / in line code for displaying file content using root directory and FAT for floppy disk.

, by Prashant Gunjal


Write an ALP / in line code for displaying file content using root directory and FAT for floppy disk.

#include<string.h>
#include<stdio.h>
#include<conio.h>
#include<DOS.h>

typedef struct        // define a structure similar to a FAT entry
 {
  char file[8];      // file name
  char ext[3];       // file extension
  char res[15];      // rserved bits
  int fclust;        // starting cluster
  char fsize[4];     // size of file
 }ent;              // name of structure

void main()
 {
  int i,j,flag=1;
  ent a[224];            // total 224 entries array of structure
  char arr[512];         // array to store file contents

  char fn[20],ex[3];       // for acceptinf file name and extension
  int log,phy;
  clrscr();               // accept file name and extension from user

  printf("\n Enter the file name whose contents are to be read : ");
  gets(fn);
  printf("\n Enter the extension of above file : ");
  gets(ex);
// code to read all 224 entries from root directory
  asm{
    mov al,1          // drive number
    mov cx,14         // number of clusters to read
    mov dx,19         // starting cluster number
    lea bx,a           // array to store entries
    int 25h
   }

  for(i=0;i<224;i++)
   {
    for(j=0;j<8;j++)
     {
      if(a[i].file[j]==' ')
       {                        // enter null character to form a string
a[i].file[j]='\0';
       }
     }
     if(strcmpi(a[i].file,fn)==0)      // check if equal
      {
       printf("\n File name found !!");
       a[i].ext[3]='\0';
       if(strcmpi(a[i].ext,ex)==0)       // check for extension
{
printf("\n\n Extension Found !!");
flag=0;
break;              // if found then break loop i
}
       else
{
printf("\n Extension not found !!");
getch();
exit();         // else exit
}
      }
   }

  if(flag==1)
   {
    printf("\n File not found !!");
    getch();             // if unsuccessful exit
    exit();
   }
     // get logical cluster (starting cluster)
  log=a[i].fclust;
  printf("\n\n Logical cluster ( starting ) number : %d",log);
  phy=log+31;            // calculate the actual cluster (physical)

  if(phy<4095)
   {
    asm{                 // code for reading contents of cluster
      mov al,1
      mov cx,1
      mov dx,phy
      lea bx,arr
      int 25h              // print the contents of file
     }
    printf("\n\n File Contents : ");
    printf("%s",arr);
   }

  getch();
 }

/* OUTPUT

 Enter the file name whose contents are to be read : abc

 Enter the extension of above file : txt

 File name found !!

 Extension Found !!

 Logical cluster ( starting ) number : 2

 File Contents : hello...welcome to mmcoe */

0 comments: