Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <cs50.h>
- #include <math.h>
- #include <ctype.h>
- /*
- In a file called letterlocator.c write a program that
- prompts the user for an alphabetic character, and then
- prints the position of that letter in the alphabet, starting
- with A at position 0. Your program should work for both capital
- and lowercase letters, but should reject any input that is not
- alphabetical, like '3' or '$'.
- GetChar
- isalpha
- */
- char alpha;
- int alphaPos(int shiftedalpha);
- int main(void)
- {
- int answer = alphaPos(alpha);
- printf("The letter %c equals %i\n\n",alpha,answer);
- }
- int alphaPos(int shiftedalpha)
- {
- do
- {
- printf("Enter an alphabet character please:\n");
- alpha = GetChar();
- } while (!isalpha(alpha));
- alpha = toupper(alpha);
- shiftedalpha = alpha-65;
- return shiftedalpha;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement