Hi,
I'm about to start making some little program with input of type string which'll later be converted into numbers, but it has to pass the check is there any non-digit character.
Considering I was lazy to search for functions like that I decided to make my own header for it.
So here it is, what do you think:
stringcheck.h :
#include <cstdlib>
#include <iostream>
using namespace std;
int HasChars(string mystring){
int length;
length=mystring.length()-1;
int cti; (char to int)
while(length>=0){
cti=(int)mystring[length]-48;
switch(cti){
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
break;
default:
return true;
break;
}
length--;
}
return false;
}
So using of it looks like:
string number;
cin>>number;
if (HasChars(number))
cout<<"It contains characters"<<endl;
else
cout<<"Nope, it doesn't contain characters"<<endl;
P.S. Function name root: I was inspired with "isdigit" "isalpha" :D