关于字符串变对应小数的问题?
#include<stdio.h>#include<ctype.h>
int get_letter(char);
int main(void)
{
char ch;
printf("Enter a string by analysis:");
scanf("%c",&ch); //输入C
printf("Now %c No. %d\n",ch,get_letter(ch));
return 0;
}
int get_letter(char ch)
{
if(isalpha(ch))
return tolower(ch)-'a'+1; //如果输入的是c为毛返回的是3?应该是c才对吧?我的理解是c-a=b;b+1=c;
else
return -1;
}