2

I have a a homework, and my professor said some of the students figured out that they could check whether the characters they read in are specific ones using a function. He said it was in the string.h library, but I checked and I don't see it. Can anybody point me in the right direction?

Andy
  • 10,553
  • 21
  • 75
  • 125

4 Answers4

5

Can anybody point me in the right direction?

Look into the standard header ctype.h.

Side note, most of them are usually implemented as macros, see Plauger.

cnicutar
  • 178,505
  • 25
  • 365
  • 392
  • Thanks! New to C so I am not sure about where to access all the libraries or what all of them even are. Appreciate the link. – Andy Feb 22 '12 at 22:06
1

The function isalpha can help you out finding the rest of them.

char c;
scanf("%c", &c);
if (isalpha(c))
  printf("You entered a letter of some alphabet\n"); 
jørgensen
  • 10,149
  • 2
  • 20
  • 27
Eregrith
  • 4,263
  • 18
  • 39
  • Thanks! I appreciate the added visual plus the link. – Andy Feb 22 '12 at 22:07
  • @jørgensen is `isalpha` localized? For example if you enter an ascii-extended character like é, is `isalpha('é')` true? (I don't even know if you can do `'é'` ... XD) – Eregrith Feb 23 '12 at 08:43
0

Check isalpha and isdigit functions.

ouah
  • 142,963
  • 15
  • 272
  • 331
0

Could be strspn.

size_t strspn(const char *s, const char *accept);

The strspn() function calculates the length of the initial segment of s which consists entirely of characters in accept.

jweyrich
  • 31,198
  • 5
  • 66
  • 97