#include <iostream>
using namespace std;
int isNumericString(unsigned char *num)
{
int i=0;
while (*(num+i)) {
if (*(num+i) >= '0' && *(num+i) <= '9')
i++;
else
return 0;
}
return 1;
}
int main()
{
int ret = 0;
unsigned char str1[] = "123";
unsigned char str2[] = "ABC";
ret = isNumericString(str1);
if(ret)
cout<<"It is numeric string"<<endl;
else
cout<<"It is not numeric string"<<endl;
ret = isNumericString(str2);
if(ret)
cout<<"It is numeric string"<<endl;
else
cout<<"It is not numeric string"<<endl;
return 0;
}
Output
It is numeric string
It is not numeric string
See the program; here str1 contains numeric string while str2 does not contain numeric string. Program is validating the string as numeric or not.
Consider the program:
Output
See the program; here str1 contains numeric string while str2 does not contain numeric string. Program is validating the string as numeric or not.
need an explanation for this answer? contact us directly to get an explanation for this answer