编写一程序将用户输入的数字字符和非数字字符组成的字符串中的数字提取出来,例如输入“asd123rt456,fg789",则产生的数字分别是123,456和789。并将提出的数据存入一个数组,以每行5个在屏幕上输出
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <string.h>
int main()
{
char str[1024] = {""};
// 输入
scanf("%s", str);
// 输出
int cnt = 0;
for(int j = 0; j < strlen(str); j++)
{
if (str[j] > '0' && str[j] < '9')
{
cnt += 1;
printf("%c", str[j]);
if(cnt == 5){
puts("");
cnt = 0;
}
}
}
puts("");
return 0;
}
手打不易,对你有帮助的话给个关注呗😁