从键盘输入字符串,字符串中含大写字母,小写字母,以及其他字符。编写程序将大写字母,小写字母,其他字符按顺序分离并分别保存在3个字符数组中,原字符数组保持不变。要求:(1)用3个子函数分别实现写字母,小写字母,其他字符的分离(2)子函数形式参数为指向性字符的指针变量(3)主函数中调用三个子函数实现各个字符的分离并显示原字符及3类分离后的字符。具体参照图片。
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;
}
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 mmocr的训练错误,结果全为0
- ¥15 python的qt5界面
- ¥15 无线电能传输系统MATLAB仿真问题
- ¥50 如何用脚本实现输入法的热键设置
- ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
- ¥30 深度学习,前后端连接
- ¥15 孟德尔随机化结果不一致
- ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
- ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
- ¥15 谁有desed数据集呀