I need to read data from a file for assignment, unfortunately, instead of spaces separating the various fields, there are null characters. When I take integers from a file, they are extracted perfectly, but with strings I just get spaces and garbage from my uninitialized array of characters. Any ideas how to just extract the characters into my character array, ignoring the empty characters.
EDIT:
char fName[15],lName[15],pMethod[5],roomType[10],purpose[15];
int days, roomNum;
long guestID;
datafile>>guestID;
datafile.getline(fName,15,'\0');
datafile.getline(lName,15,'\0');
cout<<guestID<<endl;
cout<<fName<<endl;
cout<<lName<<endl;
is the code that I am using now, unfortunately, fName does not capture anything except zero and lName gets the value of the string fName. I thought about just getting the numbers as a string and converting them.
source
share