#include <QtCore/QCoreApplication>
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<cctype>
using namespace std;
void test()
{
int arr[10];
int size = 0;
int i = 0;
char str[] = "12 45 1666";
for(;;)
{
while(str[i]!='\0' && str[i]==' ')i++;
if(str[i]=='\0')return;
arr[size] = 0;
while(str[i]!='\0' && str[i]!=' ')
{
if(!isdigit(str[i]))
{
cout <<str[i]<<" - Not a number!"<<endl;
return;
}
arr[size]=arr[size]*10+(str[i]-48);
i++;
}
size++;
}
for(int k = 0;i<size;k++)
{
cout <<arr[k]<<endl;
}
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
test();
return a.exec();
}
Here I'm trying to write a programm which convert string of figures and spaces to numeral array, but there is a problem it doesn't output. What could cause this problem. I'm a begginer to c++ so critics is welcome.
char str[]->std::stringorstd::array<char>. 2) I highly encourage you to learn how to use a debugger