从键盘输入字符串,字符串中含大写字母,小写字母,以及其他字符。编写程序将大写字母,小写字母,其他字符按顺序分离并分别保存在3个字符数组中,原字符数组保持不变。要求:(1)用3个子函数分别实现写字母,小写字母,其他字符的分离(2)子函数形式参数为指向性字符的指针变量(3)主函数中调用三个子函数实现各个字符的分离并显示原字符及3类分离后的字符。具体参照图片。
考试题请大神帮忙写一下
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
5条回答 默认 最新
码上见真晓 2017-01-04 09:18关注没什么难度,好心点给你代码吧
#include
#includevoid AtoZ(const char *p)
{
int i = 0;
char q[50] = {0};
while(*p != '\0')
{
if (*p >= 'A' && *p <= 'Z')
{
q[i] = *p;
i++;
}
p++;
}
q[i] = '\0';
printf("AtoZ: %s\n", q);
return;
}void atoz(const char *p)
{
int i = 0;
char q[50] = {0};
while(*p != '\0')
{
if (*p >= 'a' && *p <= 'z')
{
q[i] = *p;
i++;
}
p++;
}
q[i] = '\0';
printf("atoz: %s\n", q);
return;
}void other(const char *p)
{
int i = 0;
char q[50] = {0};
while(*p != '\0')
{
if (!(*p >= 'A' && *p <= 'Z')&&!(*p >= 'a' && *p <= 'z'))
{
q[i] = *p;
i++;
}
p++;
}
q[i] = '\0';
printf("other: %s\n", q);
return;
}int main(int argc, char const *argv[])
{
char str[50] = {0};printf("please input any string you want!\n"); scanf("%s",str); getchar(); char *p = str; //printf("cut out 'A' to 'Z'\n"); AtoZ(p); //printf("cut out 'a' to 'z'\n"); atoz(p); //printf("cut out the other\n"); other(p); return 0;}
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报