character validation


 
Thread Tools Search this Thread
Top Forums Programming character validation
# 1  
Old 04-28-2002
character validation

how do i validate against charcaters in c ta
# 2  
Old 04-29-2002
Ruffenator,

I read your other post as well but I am not sure what you're asking...it isn't hard to validate values (x >=1 && x <=3, etc) so I am not sure what you're really asking.

You probably want to put up some code for us to help you or explain better? You are coding in C? Korn shell? What?
# 3  
Old 04-29-2002
help

right guys i am coding in c yes

here is the exact problem i am asking for a number 1 - 3 to be entered, and i only want them to input 1 - 3, i have validated against input of numbers outside that range and need to know how to validate against a charcater being entered, hope this helps
# 4  
Old 04-29-2002
So you have already checked that they've entered numbers between 1 and 3?

Then what you are saying is
if (x == '1') {
do something;
}
if (x =='2' {
do s/t;
etc...

better yet...

switch (x) {
case '1':
{
do something:
}
break;
case '2':

{
do something:
}
break;
case '3':

{
do something:
}
break;
default:
printf("Please enter values between 1 and 3!");
break;
}

Let me know if this helps or if I understand.

Gianni
# 5  
Old 04-30-2002
not really mate, cause what i am doing is, they enter a number, which must be 1 - 3 if it is it does something, else it prints an error i can do it for outside the limits but not for charcter input.
# 6  
Old 04-30-2002
I still don't understand what the issue is but you can look at:

isalpha(c)
islower(c)
tolower(c)
isupper(c)
toupper(c)
isdigit(c)
isalnum(c)

and maybe use a combination or one or several to get what you want...(ex, if isalpha() returns TRUE(non-zero) then use tolower(c) make make all entries lowercase then do your comparison...)

Good luck.
# 7  
Old 04-30-2002
lets see

right then to make this super clear dude

if (vert >3)
{
prinf("too big\n");
printf("re-enter\n");
}
else if (vert <1)
{
printf("too small\n");
printf("please re-enter\n");
}
else
printf("well don correct");



but if the person enters a character the program crashes , any help at all
ian
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed searches a character string for a specified delimiter character, and returns a leading or traili

Hi, Anyone can help using SED searches a character string for a specified delimiter character, and returns a leading or trailing space/blank. Text file : "1"|"ExternalClassDEA519CF5"|"Art1" "2"|"ExternalClass563EA516C"|"Art3" "3"|"ExternalClass305ED16B8"|"Art9" ... ... ... (2 Replies)
Discussion started by: fspalero
2 Replies

2. UNIX for Advanced & Expert Users

Replace certain character at specific place with related character

hello i have file with 100k records and each one has certain value that starts at 28th column and certain value that starts at 88th column e.g. 1st file <25>1234567 ..... <88> 8573785485 i have aditional file with values which are related to value that starts at 88th column of the... (1 Reply)
Discussion started by: dell1520
1 Replies

3. Shell Programming and Scripting

Replace multiple occurances of same character with a single character.

Hi all, Greetings, I have the following scenario, The contents of main file are like : Unix|||||forum|||||||||||||||is||||||the||best so||||||be|||||on||||||||||||||||||||||||||||||||||||||||||||it And i need the output in the following form: Unix=forum=is=the=best so=be=on=it ... (3 Replies)
Discussion started by: dipanchandra
3 Replies

4. Shell Programming and Scripting

In Sed how can I replace starting from the 7th character to the 15th character.

Hi All, Was wondering how I can do the following.... I have a String as follows "ACCTRL000005022RRWDKKEEDKDD...." This string can be in a file called tail.out or in a Variable called $VAR2 Now I have another variable called $VAR1="000004785" (9 bytes long), I need the content of... (5 Replies)
Discussion started by: mohullah
5 Replies

5. Shell Programming and Scripting

read the text file and print the content character by character..

hello all i request you to give the solution for the following problem.. I want read the text file.and print the contents character by character..like if the text file contains google means..i want to print g go goo goog googl google like this Using unix Shell scripting... without using... (1 Reply)
Discussion started by: samupnl
1 Replies

6. UNIX for Advanced & Expert Users

if 4th and 5th character of sting -ge 45 then add 1 to 3rd character

I want to know how to, given a string like W87151WR71C, if the 4th and 5th character (in this case 15) are greater than 45, then to add 1 to the 3rd character (in this case 7) and assign the revised string the variable name MODSTRING. Thanks in advance. This is ultimately to grab info from... (6 Replies)
Discussion started by: glev2005
6 Replies

7. Shell Programming and Scripting

Deleting all characters from 350th character to 450th character from the log file

Hi All, I have a big log file i want to delete all characters (between 350th to 450th characters) starting at 350th character position to 450th character position. please advice or sample code. (6 Replies)
Discussion started by: rajeshorpu
6 Replies

8. Shell Programming and Scripting

read in a file character by character - replace any unknown ASCII characters with spa

Can someone help me to write a script / command to read in a file, character by character, replace any unknown ASCII characters with space. then write out the file to a new filename/ Thanks! (1 Reply)
Discussion started by: raghav525
1 Replies

9. AIX

check for a particular character inside a file and substitute with a given character?

i am a newbie to shell script,so i want a kshell script in which i need to check for a particular character inside a file through conditional looping(like if ,case,while)and if that character exists ,then substitute a given character to that character. consider a file test.txt,inside the file... (1 Reply)
Discussion started by: karthikprasathk
1 Replies

10. UNIX for Dummies Questions & Answers

Validation of character separated lines in a file

Hi, I have a file with "|" separated fields. If the line doesn't contain n "|" (say 2), then put this line in a file called invalid_file.txt. If it does put this row in a file called valid_file.txt. For e.g. A file contain following rows: Hi|Hello How|Are|You Hello then invalid_file.txt... (3 Replies)
Discussion started by: kolesunil
3 Replies
Login or Register to Ask a Question