473,320 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to check a string to see all the characters are number or space?

this is my code and problem is with the space between months and years::

for(;;){
char TmpAge[10];
cout<<"What age is the pet? (yy mm ) => ";
cin.getline(TmpAge,MaxChars);
if(strlen(TmpAge)==0){PetRecs[NumRecs].Age.Mths = PetRecs[NumRecs].Age.Yrs =-1; break;}
else if(is_number(TmpAge)==false){
cout<<"Invalid input1!\n"<<endl;
continue;
}
else{
sscanf(TmpAge,"%d %d",&PetRecs[NumRecs].Age.Yrs, &PetRecs[NumRecs].Age.Mths);
if( PetRecs[NumRecs].Age.Mths >= 0 &&
PetRecs[NumRecs].Age.Mths <= 11 &&
PetRecs[NumRecs].Age.Yrs >= 0 &&
PetRecs[NumRecs].Age.Yrs <= 50)
break;

else{
cout<<"Invalid input2!\n"<<endl;
continue;
}
++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++
bool is_number(char Tmp[])
{
for (int i = 0; i < MaxChars; i++) {
if (!isdigit(Tmp[i])&&((Tmp[i])!='\0')){
cout<<Tmp[i]<<" ="<<i;
return false;
}
else
continue;
}

return true;
}
Mar 27 '11 #1
1 1569
weaknessforcats
9,208 Expert Mod 8TB
You can call isdigit, isalpha or isspace using each character of the string. These functions are in ctype.h
Mar 27 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Raph | last post by:
hi, i would like export data to a DEL file, but without string characters delimiters ! Do you have some solutions or examples ? thanks Raph
2
by: José Joye | last post by:
Hello, I was wondering if there is a method that exists to replace multi-spaces within a string with single-space. eg: "12 3 4 56" --> "12 3 4 56" I think this could be done by...
2
by: kathy | last post by:
what is the better way to determine if a string is number or not?
4
by: dba_222 | last post by:
Dear Experts, Ok, I hate to ask such a seemingly dumb question, but I've already spent far too much time on this. More that I would care to admit. In Sql server, how do I simply change a...
5
by: Louna | last post by:
Hello, I need to check VAT ID Number (from IE company) to check it's valid or not in C#, how can I do this ? Some source is available ? Thank you in advanced. Regards,
3
by: palani12kumar | last post by:
hi. I want to get a string as input. If the input is an integer i want to save it to an int variable. I know to convert a number to int. but how to convert a string to number(integer). in C++
3
by: Ameet Nanda | last post by:
Hi All, I access net using a proxy, which I have to authenticate everytime I try to access net from my system. Now when I use urllib2.urlopen(url) , I cant get ahead. I must provide proxy...
10
by: Matthias | last post by:
Dear newsgroup. I want to write a template function which accepts either integer or floating point numbers. If a certain result is not a whole number and if the template parameter is an...
7
by: Archit Gupta | last post by:
i tried \w but it shows error in space...what to do... var illegalChars = /\W/; if (illegalChars.test(str))
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.