I am trying to simulate FAT8 File_Allocation_Table. FAT entries varies from -1 to 255 inclusive. Directory entry contains starting address of FAT table for a particular directory.
Whenever the starting address is greater than 127 then it's give a negative number. Negative number can be converted to +ve number by using offset. But the problem become hard for me when entry contains -1 and 255 since both gives same value.
How to handle this case ?
#include<bits/stdc++.h>
#define SIZE 256
using namespace std;
struct Dir{
char fname[SIZE]; //File Name
char start;//1st entry in FAT
char end;//Last entry in FAT
}dir;
char FAT[SIZE];
int NoOfFile;
char dfname[ ]="dir.txt";
int main(){
ofstream fout;
ifstream fin;
char name[256];
cout<<"Enter file name\n";
cin>>name;
dir.start=255;
dir.end=3;
strcpy(dir.fname,name);
fout.open(dfname);
fout.write((char*)&dir,sizeof(dir));
fout.close();
fin.open(dfname);
fin.read((char*)&dir,sizeof(dir));
cout<<dir.fname<<" "<<(int)dir.start<<" "<<(int)dir.end<<"\n";
fin.close();
return 0;
}