/*
读出字符串中的数值
如:"as-123aan856ssa-9654saa45ss-96"
分别输出:
-123
856
-9654
45
-96
*/
#include <stdio.h>
main()
{
char s[]="as-123aan856ssa-9654saa45ss-96";
char *p=s;
int a, n;
while (*p)
{
if (sscanf(p, "%d%n", &a, &n) == 1)
{
printf("%d\n", a);
p += n;
}
else
++p;
}
}
[此贴子已经被作者于2017-12-22 22:11编辑过]