#include<unistd.h>
int main()
{
char szBuf[20] = "192.168.1.100";
int m1,m2,m3,m4;
sscanf(szBuf,"%d.%d.%d.%d",&m1,&m2,&m3,&m4);
printf("m=%d,n=%d,n=%d,n=%d\n",m1,m2,m3,m4);
return 0;
}
输出结果:m=192,n=168,n=1,n=100
#include<unistd.h>
int main()
{
char szBuf[20] = "192.168.1.100";
int m1,m2,m3,m4;
sscanf(szBuf,"%d.%d.%d.%d",&m1,&m2,&m3,&m4);
printf("m=%d,n=%d,n=%d,n=%d\n",m1,m2,m3,m4);
return 0;
}
输出结果:m=192,n=168,n=1,n=100