/*6.编写一个程序,使其从标准输入读取字符,直到遇到文件结尾。对于每个字符,程序需要检查并
报告该字符是否是一个字母。如果是的话,程序还应报告该字母在字母表中的数值位置。例如,c 和 C 的
字母位置都是 3。可以先实现这样一个函数:接受一个字符参数,如果该字符为字母则返回该字母的数值
位置,否则返回-1。*/
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
int ABC(char ch);
int main(void)
{
char a;
printf("Please input a char:");
while (scanf("%c",&a) == 1)
printf("the position is: %d\n",ABC(a));
system("pause");
return 0;
}
int ABC(char n)
{
if(isalpha(n)) return toupper(n) - 'A' + 1 ;
else return -1;
}
C Primer Plus9-6
最新推荐文章于 2019-07-07 16:33:15 发布