從鍵盤輸入字符串,字符串中含大寫字母,小寫字母,以及其他字符。編寫程序將大寫字母,小寫字母,其他字符按順序分離並分別保存在3個字符數組中,原字符數組保持不變。要求:(1)用3個子函數分別實現寫字母,小寫字母,其他字符的分離(2)子函數形式參數為指向性字符的指針變量(3)主函數中調用三個子函數實現各個字符的分離並顯示原字符及3類分離後的字符。具體參照圖片。
沒什麼難度,好心點給你代碼吧
#include
#include
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 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;
}