编写一个程序,使其从标准输入读取字符,直到遇到0字符(注意是0字符,不是数字)

编写一个程序,使其从标准输入读取字符,直到遇到0字符(注意是0字符,不是数字), 对于每个字符,程序需要检查并报告字符是否是一个字母。如果是的话,程序还应该 报告该字母在字母表中的数值位置。例如,c和C的字母位置都是3。可以先实现这样一个函数:
     接收一个字符参数,如果该字符为字母则返回该字母的数值位置,否则返回-1 

 

#include <stdio.h>
int cloc(char c);
int main(){
	char c;
	int res;
	printf("请输入一个英文字符:\n");
	while(1){
		c = getchar();
		getchar();//enter也是一个字符
		if(c == '0'){
			break;
		} 
		res = cloc(c);
		if(res == -1){
			printf("input error\n");
		}
		printf("the %c is a alphaber and the char is at the place of %d\n",c,res);
	}
	return 0;
}

int cloc(char c){
	if(c<='z'&&c>='a'){
		return (c-'a'+1);
	}else if(c<='Z'&&c>='A'){
		return (c-'A'+1);
	}else
		return -1;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值