Найти наибольшее число в строке символов

Вот такой код я написал, но он выводил первое число рядка символов, а не большее. Подскажите пожалуйста где ошибка?

#include <iostream>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <cstdio>
#include <stdio.h>

int testNum (char str[]);

using namespace std;


int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    char str[999];
    cout << "\n Enter numbers separated by space: ";
    cin.getline(str,999);
    testNum (str);

    return a.exec();
}

int testNum (char str[]){
    int MAX = INT_MIN;
    for (int i=0; str[i]!='\0'; i++){
        int a = str[i];
        if (a>MAX){
            MAX=atoi(str);
        }
    }
    cout << "\n You entered: \n";
    char * pw = strtok (str," ");
    while (pw != NULL){
          cout << ' ' << pw  << "\n";
          pw = strtok (NULL, " ");
      }
    cout << "\n Max number: " << MAX;
}


Ответы (2 шт):

Автор решения: Эникейщик

Если речь о символе, то ошибка в присваивании. Нужно скорее всего так

if (a>MAX)
{ MAX=atoi(str[i]); }

Если речь о числе, то этот код не подходит совершенно.

→ Ссылка
Автор решения: Parsley

Я не понял ваш код. Но вот моя реализация. Посмотрите, возможно поможет.

#include <iostream>
#include <string>

using namespace std;
const int SIZE = 100;

int main() 
{
    char* str = new char[SIZE];
    
    cin.getline(str, SIZE);

    int max = str[1];
    for (int i = 0; i < strlen(str); i++) 
    {
        if (str[i] > max) 
        {
            max = str[i];
        }
    }
    cout << (char)max;
}
→ Ссылка