#include <stdio.h>
#define N 50
int main()
{
char str[N];
int s1[N];
float s2[N];
int temp1;
float temp2;
int i = 0;
int m = 0;
int n = 0;
float j;
printf ("请输入一个字符数组:\n");
scanf ("%s",str);
while (str[i] != '\0')
{
while ((str[i]>='0' && str[i]<='9') || (str[i] == '.')) //找数字或小数点
{
temp1 = 0;
temp2 = 0.0;
while (str[i]>='0' && str[i]<='9') //遇到数字,计算为整数
{
temp1 = temp1 * 10 + (str[i] - '0');
i++;
}
if (str[i] == '.') //判断是否是小数点
{
j = 0.1;
temp2 = temp1; //遇到小数点将之前算的整数,作为实数的整数部分
i++;
while (str[i]>='0' && str[i]<='9') //小数点后遇到数字,计算小数小数部分
{
temp2 = temp2 + (str[i] - '0') * j;
j = j * 0.1;
i++;
}
s2[m++] = temp2; //将所有实数给数组s2
}
else
{
s1[n++] = temp1; //将所有整数给数组s1
}
i++;
}
i++;
}
printf ("整数 : ");
for (i=0; i<n; i++)
{
printf ("%d ",s1[i]);
}
printf ("\n");
printf ("实数 : ");
for (i=0; i<m; i++)
{
printf ("%.5f ",s2[i]);
}
printf ("\n");
return 0;
}