Formatting strings in C

Feb 5, 2013 at 12:23am
I'm trying to write a short program that takes the input from a user and trims any leading/trailing white space, and then checks how many words are in the string. Problem is, I'm only allowed to use stdio.h and stdlib.h. How can I accomplish this? Also, how would I check if any of the characters which were entered aren't either a number, letter, or '-'?


Thanks
Feb 5, 2013 at 12:30am
if (myword[0] == ' ') Could be used to check space

if (myword[0] == '-') Could be used to check dash

if (myword[0] > 9) Could be used to check for letter

if (myword[0] <= 9) Could be used to check numbers
Last edited on Feb 5, 2013 at 12:31am
Feb 5, 2013 at 1:11am
Would it be reasonable to check an element like this then:

if( (myword[0] == ' ') || (myword[0] == '-') || (myword[0] <= 9) || (myword[0] > 9)){

// do stuff

}

Feb 5, 2013 at 1:38am
Can I just say that checking if the integer value of a character is larger than 9 won't tell you if it's a letter.

If you want to know what's whitespace, letters, numbers, etc., look it up:

http://www.asciitable.com/
Topic archived. No new replies allowed.