浅枫


私信TA

用户名:a1105054657

访问量:28395

签 名:

生命不止,奋斗不息

等  级
排  名 125
经  验 7460
参赛次数 3
文章发表 26
年  龄 21
在职情况 学生
学  校 抚顺职业技术学院
专  业 电气自动化技术专业

  自我简介:

潺潺弱弱的小菜鸡一只!

解题思路:
1)读取一串字符串存在数组做判断

2)调用isalpha()函数判断是否是字母
注意事项:

ctype.h里的函数概况:

字符测试函数:

int isalnum(int c)        该函数检查传递的字符是否是字母数字

int isalpha(int c)        该函数是否传递的字符是字母

int iscntrl(int c)        该函数是否传递的字符是控制字符

int isdigit(int c)        该函数是否传递的字符是十进制数字

int isgraph(int c)        该函数是否传递的字符的图形表示,使用的语言环境。

int islower(int c)        该函数检查传递的字符是否是小写字母

int isprint(int c)        该函数检查传递的字符是否是可打印的。

int ispunct(int c)        该函数检查传递的字符是否是标点符号

int isspace(int c)        该函数检查传递的字符是否是空白(空格)

int isupper(int c)        该函数检查传递的字符是否是大写字母

int isxdigit(int c)        该函数检查传递的字符是否是十六进制数字

该库还包含两个转换函数,也接受并返回一个“整数”


字符映射函数:

参数进行检测, 若符合范围则转换, 否则不变

int tolower(int)         范围:'A'~'Z' ==> 'a'~'z',将大写字母转换成小写字母

int toupper(int)        范围:'a'~'z' ==> 'A'~'Z',将小写字母转换成大写字母


参考代码:

#include<stdio.h>       //scanf()和printf()函数库
#include<ctype.h>        //isalpha函数库
#include<string.h>        //strlen()函数库

int main(){
	char str[80];        //存储字符数组
	int i=0;   
	scanf("%s", &str);    //读取字符串
	i = strlen(str);        //计算字符串长度,由于strlen()函数没有把字符串的“\0”算进去,所以不用-1
	for( int j=0; j<i; j++){
		if(isalpha(str[j])) printf("%c", str[j]);    //isalpha()是判断是否是字母,是字母则输出,否则跳过
	}
	
	return 0;
}


 

0.0分

19 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区

#include<stdio.h>
int main()
{
	char a[100];
	gets(a);
	char *p;
	p=a;
	while(*p!='\0')
	{
		if((*p>='a'&&*p<='z')||(*p>='A'&&*p<='Z'))
		{
			printf("%c",*p);
		}
		p++;
	}
}
2022-05-16 22:46:21
#include<stdio.h>
#include<string.h>
int main()
{
    char c[1000];
    gets(c);
    for(int i=0;i<strlen(c);i++)
        if((c[i]>='a' && c[i]<= 'z') || (c[i]>='A' && c[i]<='Z'))
            printf("%c",c[i]);
	return 0;
}
2022-01-04 12:52:06
#include <stdio.h>
#include <string.h>
int main (void)
{
	char a[80];
	int i,len;
	gets(a);
	len=strlen(a);
	for(i=0;i<len;i++)
	{
		if(!(a[i]>='a'&&a[i]<='z')||(a[i]>='A'&&a[i]<='Z'))
		{
			continue;
		}
		printf("%c",a[i]);
	}

	return 0;
}dev上运行结果正确,为什么提交错误啊
2021-11-06 16:00:25
思路很清晰
2021-04-29 19:30:43
为什么我不对》》》》》。。。。。
#include <stdio.h>
#include <ctype.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	int m,n,i,s=0,c;
	char b[1000]={'0'};
	while((c = getchar())!= '\n'){
		if(isalpha(c)){
			b[i]=c;
		    s++;
	}
}

		for(i=0;i<s;i++){
			printf("%c",b[i]);
		}
	
	return 0;
}
2020-11-10 16:42:51
大佬总结得很全面很用心啊!谢谢啦
2020-01-26 17:50:34
  • «
  • 1
  • »