char、int、float を含む構造体を構築するには、ファイルからの単一の読み取りを使用する必要があります。文字は問題なく読み取ることができますが、intの読み取りに問題があります
CountryData ReadingFile(Directory* CountryDirectory,int SortedCountryData,char *Code,int NumberofCountries)
{
int Location,i; // Will store Location in array and location in bytes
char Buff[40]; //Buffer the size of the stuct
char Tok[25];
CountryData Country;
off_t offset; //Offset value
ssize_t count;
Location = BinarySearch(CountryDirectory,Code,0,NumberofCountries-1); //Findlocation in array
Location =CountryDirectory[Location].Offset; //Find location in bytes
offset = lseek(SortedCountryData, Location, SEEK_SET); //Seek to location in file
count = read(SortedCountryData,Buff,40); //Read file
//Data in Buff should be Code[4],Name[25],int,float
for(i=0;i<4;i++)//Get code
{
Tok[i] = Buff[i];
}
strncpy(Country.Code,Tok,sizeof(Country.Code));//Copy Code
for(i=0;i<25;i++)//Get Name
{
Tok[i]=Buff[i+4];
}
strncpy(Country.Name,Tok,sizeof(Country.Name));//Copy Name
//This is where I try to read the int
char INTEGER[4];
for(i=0;i<4;i++) //Read an int
{
INTEGER[i]=Buff[33+i];
}
int A =(int)INTEGER;
printf("Tok: %d",A);
return(Country);
}