void searchSymbol(char sym, chemicalElement chemEl[]){
ifstream binFile;
unsignedshortint i=0;
binFile.open("chemicalEl.dat", ios::binary);
if(binFile.good())
cout<<"File read for search"<<endl;
while(binFile.good()){/////Here I am lost what to do and how
binFile.read((char*)&chemEl[i], sizeof(chemicalElement));
if(strcmp(chemEl[i].symbol, sym)==0 )
cout<<chemEl[i];///display all info about that element
else
i++;
}
binFile.close();
}
try to put "\n" in alterante in line 52. after chemE1.name<<\n<<..
try putting \n as i showed. It will give you the mass, namee, symbol and atomic number. See if it works.
Also why are you passing and populating the whole array? Should you just return the one item that you find? void searchSymbol(char &sym, chemicalElement& chemEl){
Similarly, getInfo() needs to pass chemEl by reference if you want the caller to have access to the result: void getInfo(float Mass, chemicalElement& chemEl){
1 2 3 4 5 6
while(read.good()){
read>>chemEl.mass;
read>>chemEl.name;
read>>chemEl.symbol;
read>>chemEl.atomicNumber;
rite.write((char*)&chemEl, sizeof(chemicalElement));//write to binary file
This will probably fail at the end of the file. It should be:
1 2 3 4 5 6 7 8
while(true){
read>>chemEl.mass;
read>>chemEl.name;
read>>chemEl.symbol;
read>>chemEl.atomicNumber;
if (!read.good()) break;
rite.write((char*)&chemEl, sizeof(chemicalElement));//write to binary file
}
Similarly your read loop should be: while(binFile.read((char*)&chemEl, sizeof(chemicalElement))) {