I dynamically allocated string "line" because I don't know how large it will get to be.
I can assign data to line just fine, however, when I try to scan for spaces in the string, it causes a segmentation fault.
I've tried every variation of "line[pos]" I can think of, but they all fail. Any ideas?Code:string *line = new string; *line = log.getLastLogged(); int count, pos = 0; int npos = line->length(); for(int pos = 0; pos < npos; pos++) { if(line[pos] == " ") { //Segfault here pos++; count++; } else pos++; cout << count << " " << pos << endl; }
Also, can anyone can tell me why I can't do "while(line[pos] != 0)" in place of the "for" loop?