#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void main()
{
//如果是以逗号做分隔的就应该把 , 换成空格
char str[] = "51934,雷小姐,女,21,166, 办公室职员,100元/天,北京电影学院形象气质佳, 123456789, 123@qqc.om, 987654321";
for (int i = 0; i < strlen(str); i++)
{
if (str[i] == ',')
{
str[i] = ' ';
}
}
printf("%s\n", str);
//char str[] = "51934 雷小姐 女 21 166 办公室职员 100元/天 北京电影学院形象气质佳 123456789 123@qqc.om 987654321";
int id;
char name[10];
char sex[10];
int age;
int tall;
int sf[10];
char price[100];
char introduce[500];
long long phone;
char email[100];
long long QQ;
//注意使用 scanf() 与 sscanf()的区别,sscanf()是从buffer缓冲区中读取数据
//scanf(str, "%d%s%s%d%d%s%s%s%lld%s%lld", &id, name, sex, &age, &tall, sf, price, introduce, &phone, email, &QQ);
/* 是输入从buffer(缓冲区)中读取. */
sscanf(str, "%d%s%s%d%d%s%s%s%lld%s%lld", &id, name, sex, &age, &tall,sf, price,introduce,&phone,email,&QQ);
printf("%d%s%s%d%d%s%s%s%lld%s%lld\n", id, name, sex, age, tall,sf, price, introduce, phone, email, QQ);
char *pos ;
printf("%s\n", price);
char pr[] = "100岁年龄。";
//strtol:从前向后读整数,遇到非数字终止,pos:为找到第一个非数字的字符地址、10:表示进制
//为什么strtol() 第二个参数需要传递 地址,因为改变一个指针变量的值,需要指针变量的地址。
int vale = strtol(pr, &pos, 10);
printf("%d %s", vale, pos);
system("pause");
}
sscanf-的用法
最新推荐文章于 2022-05-06 14:46:12 发布