37.6k views
2 votes
Write a program that reads characters from the standard input to end-of-file. For each character, have the program report whether it is a letter. If it is a letter, also report its numerical location in the alphabet. For example, c and C would both be letter 3. Incorporate a function that takes a character as an argument and returns the numerical location if the character is a letter and that returns –1 otherwise.

1 Answer

3 votes
From stack overflow

in the C language:

#include ctype.h
int GetPosition(char c)
{
c = tolower(unsigned char(c));
if (c >= 'a' && c <= 'z') return c - 'a';
else return -1;
}
User Amruta
by
6.0k points