#include "stdio.h"
void getnum(char *in,char *out)
{
char *t = in;
char *p = out;
while(*t != '\0')
{
if(*t >= '0'&& *t <= '9')
*p++ = *t++;
else t++;
}
*p = '\0';
}
void main()
{ int i =0;
char * s = (char *)malloc(sizeof(char));
char * p = (char *)malloc(sizeof(char));
gets(s);
getnum(s,p);
printf("%s\n",p);
printf("%s",s);
}
//******************************方法二************************
#include "stdio.h"
void main()
{ int i =0;
char * s = (char *)malloc(sizeof(char));
char * p = (char *)malloc(sizeof(char));
gets(s);
while(*s != '\0')
{
if(*s >= '0'&& *s <= '9')
{*p++ = *s++;
i++;
}
else s++;
}
*p = '\0';
printf("%s\n",p-i);//要把移位的位数减去
printf("%s",s);
}
将数字从《字符串》中提取出来
最新推荐文章于 2023-02-24 11:06:00 发布