Truncating and removing characters from char array C++ -
i have txt
file looks this...
high score: 50 player name: sam number of kills: 5 map time
i want store before :
or whitespace after map
, time
1 array , after in another. both map
, time
, there nil after , want store whitespace null
.
so far, have managed read , store info temp
array. however, separating having problem with. code:
istream operator >> (istream &is, player &player) { char **temp; char **tempnew; char lineinfo[200] temp = new char*[5]; tempnew = new char*[5]; (int i=0; i<5; i++) { temp[i] = new char[200]; is.getline(lineinfo, sizeof(lineinfo)); int length = strlen(lineinfo); (int z=0; z < length; z++) { if(lineinfo[z] == '= ' ){ //how check if there nil after lastly char lineinfo [length - (z+1)] = lineinfo [length]; cout << lineinfo << endl; strncpy(temp[i], lineinfo, sizeof(lineinfo)); } else{ tempnew[i] = new char[200]; strncpy(tempnew[i], lineinfo, sizeof(lineinfo)); } } }
if need find ':'
#include <cstring>
and auto occurance = strstr(string, substring);
documentation here.
if occurance not null ptr, see if occurance @ end of line line. if not, value after :
c++ c arrays char
No comments:
Post a Comment