Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Beginner question

Name: Anonymous 2012-10-24 3:12

Hey /prog/. I have wrote a program in C that asks for the user to enter a string. How would I go about validating the input and making sure only alphabetic characters or spaces are accpeted as valid input?

Name: Anonymous 2012-10-24 3:31

Looking at the characters and seeing if they're alphabetic or whitespace.

Name: Anonymous 2012-10-24 3:33

Try looking at each character to see if they're alphabetic or spaces.

Name: OP 2012-10-24 3:56

But how would I go about doing that?  I tried to sort through the string with a for loop but I couldn't get it to work.

Name: Anonymous 2012-10-24 4:03

Create an iterator that yields each character in succession, then map that with a function that checks whether a character is alphanumeric or not. Ensure that the results are all positive.

Alternatively, just use a fucking for loop to check each character. This takes literally two lines of code no matter how verbose you write it, and is probably better fit to C.

Name: Anonymous 2012-10-24 4:11

Use the isalpha and isspace standard library functions in the ctype.h header file.

Name: Anonymous 2012-10-24 15:33

>>6
Terrible!

Don't change these.
Name: Email:
Entire Thread Thread List