qfedu-c-level/day12/d4.c

18 lines
540 B
C
Raw Permalink Normal View History

// 从字符串获取 sscanf(const char *buf, const char *format, ...);
// 从 buf 字符串按 format 格式提取数据并赋值给后面的变量地址
#include <stdio.h>
#include <stdlib.h>
int main()
{
char *content = "disen,17791692095,610039018";
char name[10] = ""; // 换行符占最后一位
long phone;
char qq[10] = "";
sscanf(content, "%5s,%ld,%9s", name, &phone, qq);
// sscanf(content, "%5s,%ld,%9s", name, &phone, qq);
printf("name: %s\nphone: %ld\nqq: %s\n", name, phone, qq);
return 0;
}