It is necessary to count the number of words in each line for further action. The function works with a regular line, but when the buffer is transferred to it, which contains (or should contain a line from the file), the function does not work and returns 1. It looks like a primitive task, but I cannot find the error. Thong, please do not offer.
Code:
int CountWords(char str[]) { int counter = 0; char* c = strtok(str, " "); while (c) { c = strtok(NULL, " "); counter++; } return counter; } void DeleteMaxWords(const char path[]) {//здесь ищу строку с макисмальным количеством слов ifstream f(path); char buf[50]; int i = 0; int _strNum = 0; int _maxWords = 0; while ( !f.eof() ) { f.getline(buf, 50); if (CountWords(buf) > _maxWords) { cout << CountWords(buf) << endl; _maxWords = CountWords(buf); _strNum = i; } ++i; //cout << _maxWords << endl; } }