Program to read file from flopy disk (FAT).

, by Engineer's Vision


Program to read file from flopy disk (FAT).


#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<dos.h>
#include<process.h>

struct dir
{
    char filename[8];
    char ext[3];
    char x1[15];
    int start_cluster;
    char x2[4];
};

void main()
{
    int flag=0,i,j;
    struct dir d[224];
    char arr[512];
    char file[8];
    char ext1[3];
    int logical,physical;

    clrscr();

    printf("\n Enter file name : ");
    scanf("%s",file);
    printf("\n Enter file extension : ");
    scnaf("%s",ext1);

    asm{
    mov al,0
    mov cx,14
    mov dx,19
    lea bx,d
    int 0x25
    }

    for(i=0;i<224;i++)
    {
    for(j=0;j<8;j++)
    {
        if(d[i].filename[j]==' ')
        {
        d[i].filename[j]='\0';
        }
    }
    if(strcmpi(d[i].filename,file)==0)
    {
        printf("\n File name found ");
        d[i].ext[3]='\0';

        if(strcmpi(d[i].ext,ext1)==0)
        {
        printf("\n Extension found ");
        flag=1;
        break;
        }
        else
        {
        printf("\n Extension not found ");
        getch();
        exit(1);
        }
    }
    }

    if(flag==0)
    {
    printf("\n File not found ");
    getch();
    exit(1);
    }

    logical=d[i].start_cluster;
    printf("\n Starting cluster number is : %d ",logical);
    physical=logical+31;

    if(physical<4095)
    {
    asm{
        mov al,0
        mov cx,1
        mov dx,physical
        lea bx,arr
        int 0x25
    }
    }

    printf("\n Contents of file are : \n ");
    printf("%s",arr);
    getch();
}

0 comments: