473,379 Members | 1,520 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,379 software developers and data experts.

How to test against aplhabet input ?

i have this to check for numeric inputs, which returns then menu if a number is entered less or grater than 5 but i dont know how to do this with alphabets ? for any alphabet or any other charterer apart from numbers should return the menu

Expand|Select|Wrap|Line Numbers
  1. while (select < 1 || select > 5) ;
  2.             return select;
  3.  
  4.  
  5.  
Jan 12 '11 #1
6 1529
Banfa
9,065 Expert Mod 8TB
Look up the functions in ctype.h such as isalpha
Jan 12 '11 #2
donbock
2,426 Expert 2GB
Are you asking how to work with character constants, when select is a char?

You could do this
Expand|Select|Wrap|Line Numbers
  1. if ((select < '1') || (select > '5'))
but this code assumes that the character codes for the digits 1-5 are contiguous. That is true for ASCII, but it may not be true for other character encodings.

A fully portable solution would be something more like this:
Expand|Select|Wrap|Line Numbers
  1. while (1) {
  2.    switch (select) {
  3.       case '1':
  4.       case '2':
  5.       ...
  6.       case '5':
  7.          break;
  8.       default:
  9.          return select;
  10.       }
  11.    ...
  12.    }
The switch could be replaced with an if statement.
Jan 12 '11 #3
Banfa
9,065 Expert Mod 8TB
but this code assumes that the character codes for the digits 1-5 are contiguous. That is true for ASCII, but it may not be true for other character encodings.
Actually the C standard requires that character constants for the digits be contiguous or rather that '2' - '1' = 1, '3' - '2' = 1 etc.

It is the letters you have to beware of, the standard makes no requirement on contiguity on the alphabet so 'b' - 'a' does not necessarily equal 1.
Jan 12 '11 #4
the first one works but for example if i enter 1p it executes 1 and automatically executes p as well because i have when someone enters 1 it lets the user create a file which prompts them to enter the file name they want which would automatically be p. i hope that made sense

the example with the switch does not work at all for me it when a user enters a number it just goes strait to default and returns select
Jan 12 '11 #5
weaknessforcats
9,208 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. switch (select) { 
  2.       case '1': 
  3.       case '2': 
A '1' is the ASCII character.
A 1 is the integer 1.
You cannot enter the character for 1. It is the integer you enter.

The loop should be:

Expand|Select|Wrap|Line Numbers
  1. switch (select) { 
  2.       case 1: 
  3.       case 2: 
  4. etc...
Jan 12 '11 #6
donbock
2,426 Expert 2GB
"... but i dont know how to do this with alphabets ? for any alphabet or any other charterer apart from numbers should return the menu"
How do you want to use non-numeric values?
Jan 13 '11 #7

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

Similar topics

8
by: Reply Via Newsgroup | last post by:
Folks, I am using Apache 1.3.x with PHP 4.3.x and MySQL v4. Short question: Before I put my web form available on the internet, how can I test it from mis-use in such that special characters...
2
by: Don | last post by:
Can't figure this one out. The "validate" function below checks to make sure the field "names" is not null. "validate" actually calls "isEmpty", which scans the field. Here's the situation. ...
4
by: chirs | last post by:
I try to test a field to see if it's empty. But it prints "It is not null". Why and how can I fix it? <html> <head> </head> <body> <input type="text" name="box1"> <script>
10
by: CES | last post by:
All, I'm having a problem returning focus back to an input field in Netscape. The code works in IE and Opera but not in netscape6+. Basically I have a function that is called upon...
9
by: Steve Sargent | last post by:
Hi: I'm trying to debug the following code, and it keeps looping on the if statement: public static bool operator == (OnlineMemberNode first, OnlineMemberNode second) { if(first == null) {
3
by: Kermit Piper | last post by:
Hello everyone, OK, let me try and explain again please. Here is what I'm trying to do. I have a 12-digit (UPC-A) javascript validation script which works great. All I need now is a similar...
8
by: ais523 | last post by:
I use this function that I wrote for inputting strings. It's meant to return a pointer to mallocated memory holding one input string, or 0 on error. (Personally, I prefer to use 0 to NULL when...
4
by: istillshine | last post by:
I have a function foo, shown below. Is it a good idea to test each argument against my assumption? I think it is safer. However, I notice that people usually don't test the validity of...
4
by: jehugaleahsa | last post by:
Hello: What is the best way to test my methods that hit a database? I believe tests should be as automated as possible. However, I'm not sure how I can test against a database since changes...
22
by: Voodoo Jai | last post by:
I have a page the uses a form to pass a postcode to another page and I want to test it against an SQL Injection. What would be a safe (i.e NO DELETING of data ) statement to try and how would I...
1
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.