#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
//切割不同间隔符的方法:
//第一种办法将分隔符替换为空格
//第二种办法集合
//scanf //________
//sscanf
//fscanf
//第一种:
void main1()
{
char name[100] = { 0 };
char pass[100] = { 0 };
char mail[100] = { 0 };
scanf("%%s%s%s", name,pass,mail); //输入每个字符串,用空格隔开。
printf("name=%s--pass=%s--mail=%s", name, pass, mail);
system("pause");
}
//第二种:
void main2()
{
char strall [300]= "123sadsadasdas# 45613213213#yincheng01@163.com
";
char name[100] = { 0 };
char pass[100] = { 0 };
char mail[100] = { 0 };
//"%[0-9A-Za-z] 读取一个集合,只接受数字和字母。 %*[^0-9A-Za-z]读取所有的非数字和字母的字符,“*”表示忽略后面的东西
sscanf(strall,"%[0-9A-Za-z]%*[^0-9A-Za-z]%[0-9A-Za-z]%*[^0-9A-Za-z]%[0-9A-Za-z@.]%*[^0-9A-Za-z]", name,pass,mail);
printf("name=%s--pass=%s--mail=%s", name, pass, mail);
system("pause");
}
void main()
{
FILE *pf = fopen("Z:\I\尹成清华终极版C语言视频源码文档20150131\大数据相关数据\csdn.txt", "r");
for (int i = 0; i < 100; i++)
{
char name[100] = { 0 };
char pass[100] = { 0 };
char mail[100] = { 0 };
//fscanf(pf, "%[0-9A-Za-z]%*[^0-9A-Za-z]%[0-9A-Za-z]%*[^0-9A-Za-z]%[0-9A-Za-z@._]%*[^0-9A-Za-z]", name, pass, mail);
char allstr[500] = { 0 };
fgets(allstr, 500, pf);
sscanf(allstr, "%[0-9A-Za-z_]%*[# ]%[0-9A-Za-z_]%*[# ]%[0-9A-Za-z@._]%*[^0-9A-Za-z]", name, pass, mail);
printf("%s %s %s
", name, pass, mail);
//zdg # 12344321 # zdg@csdn.net
}
fclose(pf);
system("pause");
}