#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
struct people
{
char name[10];
float score;
int age;
};
int main()
{
struct people s = { "小亮", 98.5, 16 };
struct people tmp = { 0 };
char buf[1024] = { 0 };
/*把格式化的数据转换成字符串存储到buf--sprintf*/
sprintf(buf, "%s %f %d", s.name, s.score, s.age);
/*从buf中读取格式化的数据存到tmp中--sscanf*/
sscanf(buf, "%s %f %d", &(tmp.name), &(tmp.score), &(tmp.age));
printf("%s\n", buf);
printf("%s %f %d\n", tmp.name, tmp.score, tmp.age);
return;
}
程序运行结果: