I have a .txt
file that looks like this...
City- Madrid
Colour- Red
Food- Tapas
Language
Rating
Basically, I want to add everything before the -
or end of line (whitespace) into one array and everything after into a second array.
My code adds everything before the -
or whitespace
to one array fine but not the rest.
{
char** city;
char** other;
city = new *char[5];
other = new *char[5];
for (int i=0; i<5; i++){
city = new char[95];
other = new char[95];
getline(cityname, sizeof(cityname));
for(int j=0; j<95; j++){
if(city[j] == '-'){
city[j] = city[95-j];
}
else{
other[j] = city[j]; // Does not add the everything after - character
}
}
}
Would really appreciate it if someone could help me with the else statement.
If you're going to write C++ code, the easiest thing to do would be to just use
std::string
. That way:If you want to stick with C-style strings, then you should use
strchr
:But really prefer
std::string
.