71.sscanf数据挖掘

  • 数据挖掘
    1  sscanf(str, "%d %s %s %d %d %s %s %s", &ph[i].id, ph[i].name, ph[i].sex, &ph[i].age, &ph[i].tall, ph[i].study, ph[i].mary, ph[i].where);

完整代码

 1 #define _CRT_SECURE_NO_WARNINGS
 2 #include<stdio.h>
 3 #include <stdlib.h>
 4 
 5 char path[256] = "批量级别NASA.txt";
 6 
 7  typedef struct info
 8 {
 9      //总字符串
10     char allstr[2048];
11     //id
12     int id;
13     //姓名
14     char name[10];
15     //性别
16     char sex[3];
17     //年龄
18     int age;
19     //身高
20     int tall;
21     //学习情况
22     char study[10];
23     //是否结婚
24     char mary[10];
25     //居住地
26     char where[10];
27 }H,*PH;
28 
29  PH ph;
30 
31  void init()
32  {
33      //开辟空间
34       ph = calloc(100, sizeof(H));
35      //127740    1小姐    女    22    166    本科    未婚    合肥    山羊座    编辑    普通话    安徽,浙江,江苏,上海    面议元/天    初次接触    商务伴游,私人伴游,交友伴游,景点伴游    本人今年22岁,半年前大学毕业,平时在上海工作,放假时回安徽。有意可以联系我哦。另外我是大叔控。。。    0:00—23:00    15755106787    1718560307@qq.com    http://www.banyou.com/    1718560307
36 
37       //以读的方式打开文件
38      FILE *pf = fopen(path, "r");
39      for (int i = 0; i < 101; i++)
40      {
41          char str[2048] = { 0 };
42          //读取一行
43          fgets(str, 2048, pf);
44          strcpy(ph[i].allstr, str);//拷贝总串
45          sscanf(str, "%d %s %s %d %d %s %s %s", &ph[i].id, ph[i].name, ph[i].sex, &ph[i].age, &ph[i].tall, ph[i].study, ph[i].mary, ph[i].where);
46      }
47 
48      fclose(pf);
49  }
50 
51 
52  void main()
53  {
54      init();
55 
56      for (int i = 0; i < 100;i++)
57      {
58          if (strcmp(ph[i].mary,"已婚")==0)
59          {
60              printf("%s
", ph[i].allstr);
61          }
62      }
63      system("pause");
64  }
原文地址:https://www.cnblogs.com/xiaochi/p/8453817.html