//题目:输出字符串里数字团,以及个数。比如89cy129//就输出89,129,一共2个数。// 问题:后面一大段为啥要复制粘贴前面一大段的代码?//有什么用?求解释。而且运行也不对,求修改!跪谢!
int main()
{ char str[80],*pstr;
int m,i=0,j=0,k=0,digit=0,ndigit=0,e10,a[80],*pa; pstr=&str[0];pa=&a[0]; gets(str);while(*(pstr+i)!= '\0') { if((*(pstr+i)>='0')&&(*(pstr+i)<='9')) j++; else { if(j>0) { digit=*(pstr+i-1)-48; k=1; } if(k0) digit=(*(pstr+i-1)-48); k=1; if(k<j) { e10=1; for(m=1;m<=k;m++) e10=e10*10; digit=digit+*((pstr+i-1-k)-48)*e10; k++; pa=digit; ndigit++; pa++;//这里为什么要把第一段代码复制粘贴一次? j=0; //求解释! } pa=&a[0];printf("There are %d numbers:\n",ndigit);j=0;for(j=0;j<ndigit;j++) printf("%d,",(pa+j));printf("\n");}
#include "stdio.h"
#include "stdlib.h"
int main()
{
char s[] = "123ss456w7";
int nShow = 1;
for (int i = 0; i < (int)strlen(s); i++)
{
if (s[i] >= '0' && s[i] <= '9')
{
printf("%c", s[i]);
nShow = 1;
}
else
{
if (nShow) printf("\n");
nShow = 0;
}
}
}
谭浩强,呵呵。
参考:
http://www.zhihu.com/question/22793863
输出
123
456
7
参考:
http://codepad.org/YoB3dM1r
你确定你给的代码没抄错?我这边看了各种问题。另外,这格式也太差了。
#include "stdio.h"
#include "stdlib.h"
int main()
{
char s[] = "123ss456w7";
int nShow = 1;
for (int i = 0; i < (int)strlen(s); i++)
{
if (s[i] >= '0' && s[i] <= '9')
{
printf("%c", s[i]);
nShow = 1;
}
else
{
if (nShow) printf("\n");
nShow = 0;
}
}
}
我把你代码贴了下来,你的代码你确定没有抄错,,,