输入一个字符串并从中找出连续最长的数字字符串,将该数字字符串并长度打印出来。
#include
void main()
{
char input[100];
char output[100] = {0};
int count = 0, maxlen = 0, i = 0;
char *in=input, *out=output,*temp=NULL,*final=NULL;
printf("Please input string(length under 100):\n");
scanf("%s", input);
printf("Input string is %s\n", input);
while(*in!='\0')
{
if(*in>='0'&&*in<='9')
{
count=0;
temp=in;
for(;(*in>='0')&&(*in<='9');in++)
count++;
if (maxlen
{
maxlen=count;
final=temp;
}
}
in++;
} // while
fo r(i=0; i
*(out++) = *(final++);
*out='\0';
printf("Maxlen is %d\n", maxlen);
printf("Output is %s\n", output);
}
/*-- E --*/
谢谢欣赏!
阅读(2886) | 评论(0) | 转发(0) |