KazIT
asked on
problems opening a binary file to screen for viewing.
Hi,
I have a code that requires a birnary file to be opened for output to the screen but when I execute the code it says "File can not be opened"
here is my code
int readBinaryRecord(BirdRecor d all[],string option,BirdLocationAllWrit e BirdOrLocationOrAll)
{
ifstream inFile;
inFile.open(inFileName,ios ::binary);
if(inFile.fail() )
{
cerr<<"FILE "<<inFileName<<" Could not be Opened ";
getch();
exit(1);
}
int idx=0;
BirdRecord birds;
while(! ( inFile.eof() ) )
{
inFile.read(reinterpret_ca st<char*>( &birds),si zeof(birds ) ); //Read a binary record.
if(BirdOrLocationOrAll== BIRD )//for option 3, that is view sightings on the basis of a particular type of birds.
{
if(birds.type==option)
{
all[idx].firstDate=birds.f irstDate;
all[idx].firstMonth=birds. firstMonth ;
all[idx].firstYear=birds.f irstYear;
all[idx].latestDate=birds. latestDate ;
all[idx].latestMonth=birds .latestMon th;
all[idx].latestYear=birds. latestYear ;
strcpy(all[idx].type,birds .type);
strcpy(all[idx].location,b irds.locat ion);
all[idx].numberOfBirds=bir ds.numberO fBirds;
idx++;
}
}
if(BirdOrLocationOrAll==LO CATION)//f or option 4, that is view sightings on the basis of a particular type of location.
{
if(birds.location==option)
{
all[idx].firstDate=birds.f irstDate;
all[idx].firstMonth=birds. firstMonth ;
all[idx].firstYear=birds.f irstYear;
all[idx].latestDate=birds. latestDate ;
all[idx].latestMonth=birds .latestMon th;
all[idx].latestYear=birds. latestYear ;
strcpy(all[idx].type,birds .type);
strcpy(all[idx].location,b irds.locat ion);
all[idx].numberOfBirds=bir ds.numberO fBirds;
idx++;
}
}
if(BirdOrLocationOrAll==AL L)//for option 5, view all birds in all location.
{
all[idx].firstDate=birds.f irstDate;
all[idx].firstMonth=birds. firstMonth ;
all[idx].firstYear=birds.f irstYear;
all[idx].latestDate=birds. latestDate ;
all[idx].latestMonth=birds .latestMon th;
all[idx].latestYear=birds. latestYear ;
strcpy(all[idx].type,birds .type);
strcpy(all[idx].location,b irds.locat ion);
all[idx].numberOfBirds=bir ds.numberO fBirds;
idx++;
}
}
return idx;
}
there is a header file with
const char inFileName[] = "birds.bin";//name of file
thanks
Kaz
I have a code that requires a birnary file to be opened for output to the screen but when I execute the code it says "File can not be opened"
here is my code
int readBinaryRecord(BirdRecor
{
ifstream inFile;
inFile.open(inFileName,ios
if(inFile.fail() )
{
cerr<<"FILE "<<inFileName<<" Could not be Opened ";
getch();
exit(1);
}
int idx=0;
BirdRecord birds;
while(! ( inFile.eof() ) )
{
inFile.read(reinterpret_ca
if(BirdOrLocationOrAll== BIRD )//for option 3, that is view sightings on the basis of a particular type of birds.
{
if(birds.type==option)
{
all[idx].firstDate=birds.f
all[idx].firstMonth=birds.
all[idx].firstYear=birds.f
all[idx].latestDate=birds.
all[idx].latestMonth=birds
all[idx].latestYear=birds.
strcpy(all[idx].type,birds
strcpy(all[idx].location,b
all[idx].numberOfBirds=bir
idx++;
}
}
if(BirdOrLocationOrAll==LO
{
if(birds.location==option)
{
all[idx].firstDate=birds.f
all[idx].firstMonth=birds.
all[idx].firstYear=birds.f
all[idx].latestDate=birds.
all[idx].latestMonth=birds
all[idx].latestYear=birds.
strcpy(all[idx].type,birds
strcpy(all[idx].location,b
all[idx].numberOfBirds=bir
idx++;
}
}
if(BirdOrLocationOrAll==AL
{
all[idx].firstDate=birds.f
all[idx].firstMonth=birds.
all[idx].firstYear=birds.f
all[idx].latestDate=birds.
all[idx].latestMonth=birds
all[idx].latestYear=birds.
strcpy(all[idx].type,birds
strcpy(all[idx].location,b
all[idx].numberOfBirds=bir
idx++;
}
}
return idx;
}
there is a header file with
const char inFileName[] = "birds.bin";//name of file
thanks
Kaz
This might be a trivial question. Is the header file included in the codefile?
Also, do you have permissions to open the file?
ASKER
lemmeC...yes that header file is included.
How do I know if i have permissions to open the file? I can click on it in the project and it opens ok...but other than that I'm not sure what you mean sorry.
How do I know if i have permissions to open the file? I can click on it in the project and it opens ok...but other than that I'm not sure what you mean sorry.
Try replacing:
inFile.open(inFileName,ios ::binary);
with
inFile.open(inFileName,ios ::binary|i os::in);
inFile.open(inFileName,ios
with
inFile.open(inFileName,ios
>> I can click on it in the project and it opens ok <<
Then the permissions are fine.
Then the permissions are fine.
ASKER
thanks lemmeC.
The file seems to open but I must have a problem in my function because it says the number of birds or locations are zero....and I know there are those particular records there in the binary file
The file seems to open but I must have a problem in my function because it says the number of birds or locations are zero....and I know there are those particular records there in the binary file
(1) What is the length of your file?
(2) How many BirdRecords do you expect there to be in that file?
(3) Show us your BirdRecord class/struct definition.
(4) At the beginning of your program printf or cout sizeof(BirdRecord) and see if it differs from your expectation.
My guess is that struct/class BirdRecord is not packed and that you are therefore reading the wrong number of bytes each time and that the bytes read are being read into the wrong offsets in your struct.
On a lot of compilers you can byte-pack the struct by using the #pragma pack(1) directive as follows:
--------8<--------
#pragma pack(1)
struct BirdRecord
{
// ...
};
#pragma pack()
--------8<--------
Beware that this is not portable, but it works with GCC and VC.
(2) How many BirdRecords do you expect there to be in that file?
(3) Show us your BirdRecord class/struct definition.
(4) At the beginning of your program printf or cout sizeof(BirdRecord) and see if it differs from your expectation.
My guess is that struct/class BirdRecord is not packed and that you are therefore reading the wrong number of bytes each time and that the bytes read are being read into the wrong offsets in your struct.
On a lot of compilers you can byte-pack the struct by using the #pragma pack(1) directive as follows:
--------8<--------
#pragma pack(1)
struct BirdRecord
{
// ...
};
#pragma pack()
--------8<--------
Beware that this is not portable, but it works with GCC and VC.
ASKER
This is a copy of the binary file. As you can see there are many records in this file.
ÍÔpelicansÌÌÌÌÌÌÌÌÌÌÌ Awonga DamÌÌÌÌÌÌÌÌÌÎÒwood ducksÌÌÌÌÌÌÌÌÌAwonga DamÌÌÌÌÌÌÌÌÌ6ÔÔblac k ducksÌÌÌÌÌÌÌÌAwonga DamÌÌÌÌÌÌÌÌÌ<ÎÓwhis tling ducksÌÌÌÌAwonga DamÌÌÌÌÌÌÌÌÌbÌÑmagpie geeseksÌÌÌÌAwonga DamÌÌÌÌÌÌÌÌÌd
ÎÒking fishersksÌÌÌÌAwonga DamÌÌÌÌÌÌÌÌÌÌ
Ówater fowlsksÌÌÌÌAwonga DamÌÌÌÌÌÌÌÌÌ`ÏÐdab chickssksÌÌÌÌAwonga DamÌÌÌÌÌÌÌÌÌÏ
Òspoon billsksÌÌÌÌAwonga DamÌÌÌÌÌÌÌÌÌ# Ï ÒcormorantsksÌÌÌÌAwonga DamÌÌÌÌÌÌÌÌÌM
ÏÓpelicanssksÌÌÌÌFairb urn DamÌÌÌÌÌÌÌ2ÌÔwood ducksksÌÌÌÌFairburn DamÌÌÌÌÌÌÌ]ÌÔblack ducksksÌÌÌÌFairburn DamÌÌÌÌÌÌÌø
ÌÑwhistling ducksÌÌÌÌFairburn DamÌÌÌÌÌÌÌÏ Òmagpie geeseksÌÌÌÌFairburn DamÌÌÌÌÌÌÌ/king fishersksÌÌÌÌFairburn DamÌÌÌÌÌÌÌÎÑwater fowlsksÌÌÌÌFairburn DamÌÌÌÌÌÌÌBÌÓdab chickssksÌÌÌÌFairburn DamÌÌÌÌÌÌÌZÏ Ðspoon billsksÌÌÌÌFairburn DamÌÌÌÌÌÌÌ?ÏÐcormorantsksÌÌÌÌFai rburn DamÌÌÌÌÌÌÌ>Í
ÐpelicanssksÌÌÌÌTinaroo DamÌÌÌÌÌÌÌÎÔwood ducksksÌÌÌÌTinaroo DamÌÌÌÌÌÌÌ[ÎÑblack ducksksÌÌÌÌTinaroo DamÌÌÌÌÌÌÌÎÓwhistl ing ducksÌÌÌÌTinaroo DamÌÌÌÌÌÌÌ0ÌÓmagpie geeseksÌÌÌÌTinaroo DamÌÌÌÌÌÌÌÎÔking fishersksÌÌÌÌTinaroo DamÌÌÌÌÌÌÌDÏÑwater fowlsksÌÌÌÌTinaroo DamÌÌÌÌÌÌÌÌÔdab chickssksÌÌÌÌTinaroo DamÌÌÌÌÌÌÌÙÍÔspoon billsksÌÌÌÌTinaroo DamÌÌÌÌÌÌ̉ÎÐcormorantsksÌÌÌÌTi naroo DamÌÌÌÌÌÌÌÍÓpelicanssksÌÌÌÌIva nhoe DamÌÌÌÌÌÌÌÎÑwood ducksksÌÌÌÌIvanhoe DamÌÌÌÌÌÌÌ ÏÓblack ducksksÌÌÌÌIvanhoe DamÌÌÌÌÌÌÌ
! ÌÓwhistling ducksÌÌÌÌIvanhoe DamÌÌÌÌÌÌÌ9"ÏÓmagpie geeseksÌÌÌÌIvanhoe DamÌÌÌÌÌÌÌ_#
Ï Óking fishersksÌÌÌÌIvanhoe DamÌÌÌÌÌÌÌ`$ÌÒwater fowlsksÌÌÌÌIvanhoe DamÌÌÌÌÌÌÌ%ÎÓdab chickssksÌÌÌÌIvanhoe DamÌÌÌÌÌÌÌL&ÏÓspoon billsksÌÌÌÌIvanhoe DamÌÌÌÌÌÌÌ['
ÌÔcormorantsksÌÌÌÌIvanhoe DamÌÌÌÌÌÌÌ=(ÍÑpelicanssksÌÌÌÌLake VictoriaÌÌÌÌÌÌ)Ï Òwood ducksksÌÌÌÌLake VictoriaÌÌÌÌÌÌ*Î Òblack ducksksÌÌÌÌLake VictoriaÌÌÌÌÌÌ>+ÍÑwh istling ducksÌÌÌÌLake VictoriaÌÌÌÌÌÌ ,
ÎÑmagpie geeseksÌÌÌÌLake VictoriaÌÌÌÌÌÌ-ÏÒking fishersksÌÌÌÌLake VictoriaÌÌÌÌÌÌ.
ÏÐwater fowlsksÌÌÌÌLake VictoriaÌÌÌÌÌÌ</ÏÒda b chickssksÌÌÌÌLake VictoriaÌÌÌÌÌÌ0Í Òspoon billsksÌÌÌÌLake VictoriaÌÌÌÌÌÌ+1
Î
ÐcormorantsksÌÌÌÌLake VictoriaÌÌÌÌÌÌ 2ÌÑpelicanssksÌÌÌÌBurn ett RiverÌÌÌÌÌÌ3 ÌÓwood ducksksÌÌÌÌBurnett RiverÌÌÌÌÌÌA4ÏÐblack ducksksÌÌÌÌBurnett RiverÌÌÌÌÌÌ_5ÌÐwhist ling ducksÌÌÌÌBurnett RiverÌÌÌÌÌÌY6ÍÑmagpie geeseksÌÌÌÌBurnett RiverÌÌÌÌÌÌ7Ï Ðking fishersksÌÌÌÌBurnett RiverÌÌÌÌÌÌ8 ÍÔwater fowlsksÌÌÌÌBurnett RiverÌÌÌÌÌÌD9ÍÔdab chickssksÌÌÌÌBurnett RiverÌÌÌÌÌÌ:ÏÔspoo n billsksÌÌÌÌBurnett RiverÌÌÌÌÌ̲;Ì
ÓcormorantsksÌÌÌÌBurnett RiverÌÌÌÌÌÌP< ÍÒpelicanssksÌÌÌÌBurdekin RiverÌÌÌÌÌ.=Ï
Òwood ducksksÌÌÌÌBurdekin RiverÌÌÌÌÌK>Ï Óblack ducksksÌÌÌÌBurdekin RiverÌÌÌÌÌ>?ÍÒwhistl ing ducksÌÌÌÌBurdekin RiverÌÌÌÌÌ>@ ÌÔmagpie geeseksÌÌÌÌBurdekin RiverÌÌÌÌÌ A
ÌÒking fishersksÌÌÌÌBurdekin RiverÌÌÌÌÌbBÍÑwater fowlsksÌÌÌÌBurdekin RiverÌÌÌÌÌ5CÎÐdab chickssksÌÌÌÌBurdekin RiverÌÌÌÌÌD Î
Óspoon billsksÌÌÌÌBurdekin RiverÌÌÌÌÌWEÍÑcormorantsksÌÌÌÌBurdeki n RiverÌÌÌÌÌPF
Ï
ÐpelicanssksÌÌÌÌPioneer RiverÌÌÌÌÌ9GÎÔwood ducksksÌÌÌÌPioneer RiverÌÌÌÌÌCHÌÓblack ducksksÌÌÌÌPioneer RiverÌÌÌÌÌ[I Î
Òwhistling ducksÌÌÌÌPioneer RiverÌÌÌÌÌWJÎÔmagpie geeseksÌÌÌÌPioneer RiverÌÌÌÌÌØKÏÓking fishersksÌÌÌÌPioneer RiverÌÌÌÌÌbL ÍÓwater fowlsksÌÌÌÌPioneer RiverÌÌÌÌÌSMÌÒdab chickssksÌÌÌÌPioneer RiverÌÌÌÌÌNÎÔspoon billsksÌÌÌÌPioneer RiverÌÌÌÌÌaOÏÔcormorantsksÌÌÌÌPioneer RiverÌÌÌÌ̪PÌÓpelic anssksÌÌÌÌ Mary RivererÌÌÌÌÌQÍÒwood ducksksÌÌÌÌMary RivererÌÌÌÌÌRR
ÍÒblack ducksksÌÌÌÌMary RivererÌÌÌÌÌUSÏÐwhistling ducksÌÌÌÌMary RivererÌÌÌÌÌ(TÏÓmagp ie geeseksÌÌÌÌMary RivererÌÌÌÌÌ=UÏÓking fishersksÌÌÌÌMary RivererÌÌÌÌÌVÍÐwater fowlsksÌÌÌÌMary RivererÌÌÌÌÌ W ÌÑdab chickssksÌÌÌÌMary RivererÌÌÌÌÌ_X
ÌÓspoon billsksÌÌÌÌMary RivererÌÌÌÌÌ"YÏ
ÓcormorantsksÌÌÌÌMary RivererÌÌÌÌÌZ
ÍÔpelicanssksÌÌÌÌFitzr oy RiverÌÌÌÌÌû[ ÍÐwood ducksksÌÌÌÌFitzroy RiverÌÌÌÌÌ\Í
Ñblack ducksksÌÌÌÌFitzroy RiverÌÌÌÌÌG] Î Òwhistling ducksÌÌÌÌFitzroy RiverÌÌÌÌÌO^ÎÑmagpie geeseksÌÌÌÌFitzroy RiverÌÌÌÌÌ_ Ì
Òking fishersksÌÌÌÌFitzroy RiverÌÌÌÌÌ` ÎÓwater fowlsksÌÌÌÌFitzroy RiverÌÌÌÌÌ;a
ÌÔdab chickssksÌÌÌÌFitzroy RiverÌÌÌÌÌ´bÎÐspoon billsksÌÌÌÌFitzroy RiverÌÌÌÌÌ+cÌÔcormorantsksÌÌÌÌFit zroy RiverÌÌÌÌÌY
This is a copy of BirdRecord Struct
struct BirdRecord //define a BirdRecord struct
{
int reference;//to store the key
int firstDate;//date variable store date 1st sighting
int firstMonth;
int firstYear;
int latestDate;
int latestMonth;
int latestYear;
char type[BIRD_SIZE];//constant int defined in const.h
char location[LOCATION_SIZE];// date variable store date last sighting
//constant int defined in const.h
int numberOfBirds;
};
this is a copy of the constants header file
#ifndef CONST_H
#define CONST_H
#include <string>
using std::string;
enum BirdLocationAllWrite{BIRD, LOCATION,A LL,WRITE}; //If to read for option 3, or for option 4, or for option 5, or for option 2(i.e, to write).
const int MAX_SIZE = 10 ; // Number of bird types & the number of locations
const int BIRD_SIZE = 20 ; // For printing
const int LOCATION_SIZE = 20 ; // For printing
const int LINES_PER_PAGE = 15; // To pause the display
const int MENU_CHOICES = 5;
const int MAX_NUMBER_OF_ENTRIES = 100;
// The species of birds
const string BIRD_TYPE[MAX_SIZE] = { "pelicans", "wood ducks", "black ducks", "whistling ducks",
"magpie geese", "king fishers", "water fowl", "dab chicks",
"spoon bills", "cormorants" } ;
// The locations
const string LOCATIONS[MAX_SIZE] = { "Awonga Dam", "Fairburn Dam", "Tinaroo Dam", "Ivanhoe Dam",
"Lake Victoria", "Burnett River", "Burdekin River",
"Pioneer River", "Mary River", "Fitzroy River" } ;
#endif
ÍÔpelicansÌÌÌÌÌÌÌÌÌÌÌ
ÎÒking fishersksÌÌÌÌAwonga DamÌÌÌÌÌÌÌÌÌÌ
Ówater fowlsksÌÌÌÌAwonga DamÌÌÌÌÌÌÌÌÌ`ÏÐdab chickssksÌÌÌÌAwonga DamÌÌÌÌÌÌÌÌÌÏ
Òspoon billsksÌÌÌÌAwonga DamÌÌÌÌÌÌÌÌÌ# Ï ÒcormorantsksÌÌÌÌAwonga DamÌÌÌÌÌÌÌÌÌM
ÏÓpelicanssksÌÌÌÌFairb
ÌÑwhistling ducksÌÌÌÌFairburn DamÌÌÌÌÌÌÌÏ Òmagpie geeseksÌÌÌÌFairburn DamÌÌÌÌÌÌÌ/king fishersksÌÌÌÌFairburn DamÌÌÌÌÌÌÌÎÑwater fowlsksÌÌÌÌFairburn DamÌÌÌÌÌÌÌBÌÓdab chickssksÌÌÌÌFairburn DamÌÌÌÌÌÌÌZÏ Ðspoon billsksÌÌÌÌFairburn DamÌÌÌÌÌÌÌ?ÏÐcormorantsksÌÌÌÌFai
ÐpelicanssksÌÌÌÌTinaroo DamÌÌÌÌÌÌÌÎÔwood ducksksÌÌÌÌTinaroo DamÌÌÌÌÌÌÌ[ÎÑblack
! ÌÓwhistling ducksÌÌÌÌIvanhoe DamÌÌÌÌÌÌÌ9"ÏÓmagpie geeseksÌÌÌÌIvanhoe DamÌÌÌÌÌÌÌ_#
Ï Óking fishersksÌÌÌÌIvanhoe DamÌÌÌÌÌÌÌ`$ÌÒwater fowlsksÌÌÌÌIvanhoe DamÌÌÌÌÌÌÌ%ÎÓdab chickssksÌÌÌÌIvanhoe DamÌÌÌÌÌÌÌL&ÏÓspoon billsksÌÌÌÌIvanhoe DamÌÌÌÌÌÌÌ['
ÌÔcormorantsksÌÌÌÌIvanhoe
ÎÑmagpie geeseksÌÌÌÌLake VictoriaÌÌÌÌÌÌ-ÏÒking fishersksÌÌÌÌLake VictoriaÌÌÌÌÌÌ.
ÏÐwater fowlsksÌÌÌÌLake VictoriaÌÌÌÌÌÌ</ÏÒda
Î
ÐcormorantsksÌÌÌÌLake VictoriaÌÌÌÌÌÌ 2ÌÑpelicanssksÌÌÌÌBurn
ÓcormorantsksÌÌÌÌBurnett
Òwood ducksksÌÌÌÌBurdekin RiverÌÌÌÌÌK>Ï Óblack ducksksÌÌÌÌBurdekin RiverÌÌÌÌÌ>?ÍÒwhistl
ÌÒking fishersksÌÌÌÌBurdekin RiverÌÌÌÌÌbBÍÑwater fowlsksÌÌÌÌBurdekin RiverÌÌÌÌÌ5CÎÐdab chickssksÌÌÌÌBurdekin RiverÌÌÌÌÌD Î
Óspoon billsksÌÌÌÌBurdekin RiverÌÌÌÌÌWEÍÑcormorantsksÌÌÌÌBurdeki
Ï
ÐpelicanssksÌÌÌÌPioneer RiverÌÌÌÌÌ9GÎÔwood ducksksÌÌÌÌPioneer RiverÌÌÌÌÌCHÌÓblack
Òwhistling ducksÌÌÌÌPioneer RiverÌÌÌÌÌWJÎÔmagpie geeseksÌÌÌÌPioneer RiverÌÌÌÌÌØKÏÓking fishersksÌÌÌÌPioneer RiverÌÌÌÌÌbL ÍÓwater fowlsksÌÌÌÌPioneer RiverÌÌÌÌÌSMÌÒdab chickssksÌÌÌÌPioneer RiverÌÌÌÌÌNÎÔspoon billsksÌÌÌÌPioneer RiverÌÌÌÌÌaOÏÔcormorantsksÌÌÌÌPioneer
ÍÒblack ducksksÌÌÌÌMary RivererÌÌÌÌÌUSÏÐwhistling ducksÌÌÌÌMary RivererÌÌÌÌÌ(TÏÓmagp
ÌÓspoon billsksÌÌÌÌMary RivererÌÌÌÌÌ"YÏ
ÓcormorantsksÌÌÌÌMary RivererÌÌÌÌÌZ
ÍÔpelicanssksÌÌÌÌFitzr
Ñblack ducksksÌÌÌÌFitzroy RiverÌÌÌÌÌG] Î Òwhistling ducksÌÌÌÌFitzroy RiverÌÌÌÌÌO^ÎÑmagpie geeseksÌÌÌÌFitzroy RiverÌÌÌÌÌ_ Ì
Òking fishersksÌÌÌÌFitzroy RiverÌÌÌÌÌ` ÎÓwater fowlsksÌÌÌÌFitzroy RiverÌÌÌÌÌ;a
ÌÔdab chickssksÌÌÌÌFitzroy RiverÌÌÌÌÌ´bÎÐspoon billsksÌÌÌÌFitzroy RiverÌÌÌÌÌ+cÌÔcormorantsksÌÌÌÌFit
This is a copy of BirdRecord Struct
struct BirdRecord //define a BirdRecord struct
{
int reference;//to store the key
int firstDate;//date variable store date 1st sighting
int firstMonth;
int firstYear;
int latestDate;
int latestMonth;
int latestYear;
char type[BIRD_SIZE];//constant
char location[LOCATION_SIZE];//
//constant int defined in const.h
int numberOfBirds;
};
this is a copy of the constants header file
#ifndef CONST_H
#define CONST_H
#include <string>
using std::string;
enum BirdLocationAllWrite{BIRD,
const int MAX_SIZE = 10 ; // Number of bird types & the number of locations
const int BIRD_SIZE = 20 ; // For printing
const int LOCATION_SIZE = 20 ; // For printing
const int LINES_PER_PAGE = 15; // To pause the display
const int MENU_CHOICES = 5;
const int MAX_NUMBER_OF_ENTRIES = 100;
// The species of birds
const string BIRD_TYPE[MAX_SIZE] = { "pelicans", "wood ducks", "black ducks", "whistling ducks",
"magpie geese", "king fishers", "water fowl", "dab chicks",
"spoon bills", "cormorants" } ;
// The locations
const string LOCATIONS[MAX_SIZE] = { "Awonga Dam", "Fairburn Dam", "Tinaroo Dam", "Ivanhoe Dam",
"Lake Victoria", "Burnett River", "Burdekin River",
"Pioneer River", "Mary River", "Fitzroy River" } ;
#endif
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
> if (option == string(birds.type,option.s ize())
Missing paren:
if (option == string(birds.type,option.s ize()))
Missing paren:
if (option == string(birds.type,option.s
ASKER
thanks for the comment rstaveley. After implementation of your advices the same output comes to screen....here's the exe file output
Bird Watching Records Program
-------------------------- ------
1. View sightings from the last excursion
2. Update the records with the latest sightings
3. View sightings of a particular type of bird
4. View sightings of birds in a particular location
5. View all sightings
0. Exit
-------------------------- -------
Please enter your selection: 3
1. pelicans
2. wood ducks
3. black ducks
4. whistling ducks
5. magpie geese
6. king fishers
7. water fowl
8. dab chicks
9. spoon bills
10. cormorants
Please enter your selection 1
Sightings Number
First Latest Bird Type Location of Birds
-------------------------- ---------- ---------- ---------- ---------- ---------- ----
Total No Of Birds for pelicans are 0
-------------------------- ---------- ---------- ---------- ---------- ---------- ----
Press any key to continue
Bird Watching Records Program
--------------------------
1. View sightings from the last excursion
2. Update the records with the latest sightings
3. View sightings of a particular type of bird
4. View sightings of birds in a particular location
5. View all sightings
0. Exit
--------------------------
Please enter your selection: 3
1. pelicans
2. wood ducks
3. black ducks
4. whistling ducks
5. magpie geese
6. king fishers
7. water fowl
8. dab chicks
9. spoon bills
10. cormorants
Please enter your selection 1
Sightings Number
First Latest Bird Type Location of Birds
--------------------------
Total No Of Birds for pelicans are 0
--------------------------
Press any key to continue
In your binary file, I see pelicans listed as "pelicanssksÌÌÌÌ", which makes me suspect that your binary data is corrupt. It looks like the trailing "sksÌÌÌÌ" is left over from the "whistling ducksÌÌÌÌ" entry. However, the method I described would, I expect have worked with this, if by pressing '1' you got the BIRD_TYPE[0].
Since this is a console program can you try adding the following debug to readBinaryRecord?
--------8<--------
int readBinaryRecord(BirdRecor d all[],string option,BirdLocationAllWrit e BirdOrLocationOrAll)
{
cout << "Debug: option is \"" << option << "\" and BirdOrLocationOrAll is " << BirdOrLocationOrAll << '\n';
// ... continues as before
}
--------8<--------
If that doesn't shed any light on the problem, try displaying the comparison strings.
e.g.
--------8<--------
string comparison(birds.type,opti on.size()) ;
if (option == comparison) {
cout << "Debug: option is \"" << option << "\" and matched comparison is \"" << comparison << "\"\n";
// ...as before
}
else {
cout << "Debug: option is \"" << option << "\" and unmatched comparison is \"" << comparison << "\"\n";
}
--------8<--------
Since this is a console program can you try adding the following debug to readBinaryRecord?
--------8<--------
int readBinaryRecord(BirdRecor
{
cout << "Debug: option is \"" << option << "\" and BirdOrLocationOrAll is " << BirdOrLocationOrAll << '\n';
// ... continues as before
}
--------8<--------
If that doesn't shed any light on the problem, try displaying the comparison strings.
e.g.
--------8<--------
string comparison(birds.type,opti
if (option == comparison) {
cout << "Debug: option is \"" << option << "\" and matched comparison is \"" << comparison << "\"\n";
// ...as before
}
else {
cout << "Debug: option is \"" << option << "\" and unmatched comparison is \"" << comparison << "\"\n";
}
--------8<--------
ASKER
This is the output with your debug option
Please enter your selection: 3
1. pelicans
2. wood ducks
3. black ducks
4. whistling ducks
5. magpie geese
6. king fishers
7. water fowl
8. dab chicks
9. spoon bills
10. cormorants
Please enter your selection 1
Debug: option is"pelicans" and BirdOrLocatioOrAll is0
Sightings Number
First Latest Bird Type Location of Birds
-------------------------- ---------- ---------- ---------- ---------- ---------- ----
Total No Of Birds for pelicans are 0
-------------------------- ---------- ---------- ---------- ---------- ---------- ----
Press any key to continue
Please enter your selection: 3
1. pelicans
2. wood ducks
3. black ducks
4. whistling ducks
5. magpie geese
6. king fishers
7. water fowl
8. dab chicks
9. spoon bills
10. cormorants
Please enter your selection 1
Debug: option is"pelicans" and BirdOrLocatioOrAll is0
Sightings Number
First Latest Bird Type Location of Birds
--------------------------
Total No Of Birds for pelicans are 0
--------------------------
Press any key to continue
ASKER
sorry i didn't include the second part...let me try that again
> Debug: option is"pelicans" and BirdOrLocatioOrAll is0
OK, so that sanity-checks your user-interface. Can you see what it displayed by the comparison debug?
i.e.
--------8<--------
while(! ( inFile.eof() ) )
{
inFile.read(reinterpret_ca st<char*>( &birds),si zeof(birds ) ); //Read a binary record.
if(BirdOrLocationOrAll== BIRD )//for option 3, that is view sightings on the basis of a particular type of birds.
{
if(birds.type==option)
{
string comparison(birds.type,opti on.size()) ;
if (option == comparison)
{
cout << "Debug: option is \"" << option << "\" and matched comparison is \"" << comparison << "\"\n";
// ...as before
}
else
{
cout << "Debug: option is \"" << option << "\" and unmatched comparison is \"" << comparison << "\"\n";
}
}
// ...etc
--------8<--------
OK, so that sanity-checks your user-interface. Can you see what it displayed by the comparison debug?
i.e.
--------8<--------
while(! ( inFile.eof() ) )
{
inFile.read(reinterpret_ca
if(BirdOrLocationOrAll== BIRD )//for option 3, that is view sightings on the basis of a particular type of birds.
{
if(birds.type==option)
{
string comparison(birds.type,opti
if (option == comparison)
{
cout << "Debug: option is \"" << option << "\" and matched comparison is \"" << comparison << "\"\n";
// ...as before
}
else
{
cout << "Debug: option is \"" << option << "\" and unmatched comparison is \"" << comparison << "\"\n";
}
}
// ...etc
--------8<--------
Oops bad cut, copy and pasting... this is what I meant....
--------8<--------
while(! ( inFile.eof() ) )
{
inFile.read(reinterpret_ca st<char*>( &birds),si zeof(birds ) ); //Read a binary record.
if(BirdOrLocationOrAll== BIRD )//for option 3, that is view sightings on the basis of a particular type of birds.
{
string comparison(birds.type,opti on.size()) ;
if (option == comparison)
{
cout << "Debug: option is \"" << option << "\" and matched comparison is \"" << comparison << "\"\n";
// ...as before
}
else
{
cout << "Debug: option is \"" << option << "\" and unmatched comparison is \"" << comparison << "\"\n";
}
}
// ...etc
--------8<--------
--------8<--------
while(! ( inFile.eof() ) )
{
inFile.read(reinterpret_ca
if(BirdOrLocationOrAll== BIRD )//for option 3, that is view sightings on the basis of a particular type of birds.
{
string comparison(birds.type,opti
if (option == comparison)
{
cout << "Debug: option is \"" << option << "\" and matched comparison is \"" << comparison << "\"\n";
// ...as before
}
else
{
cout << "Debug: option is \"" << option << "\" and unmatched comparison is \"" << comparison << "\"\n";
}
}
// ...etc
--------8<--------
ASKER
dont know if i am doing something wrong but I get compiler errors now one being
"illegal escape sequence" at
cout << "Debug: option is \"" << option << "\" and matched comparison is \"" << comparison << "\"\n";
"illegal escape sequence" at
cout << "Debug: option is \"" << option << "\" and matched comparison is \"" << comparison << "\"\n";
ASKER
sorry my mistake the illegal escape sequence error is now gone...but now it's picking up some of my other functions and saying "local funtion definitions are illegal" these are functions that compiled fine before????
ASKER
I think i know what this last set of errors are relating to...I have multiple copies of the same project named bird and birds and for some reason it has taken some of the files from each when it has built and I am guessing that is the reason for this latest set of errors
ASKER
My apologies rstaveley i will have to leave this for tonight....I have gotten more confused as I have gone along. I will work on getting the program back to where we spoke about and post my response tomorrow..thanks for the help
Kaz
Kaz
Have a good rest.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER