zoukankan      html  css  js  c++  java
  • 筛选出多个数据并判断

    1.sscanf和sprintf只适用于投机取巧的场合。sprintf你可以把数据整理好了,在内存里把它写进去会很容易的。读取的时候,多一个少一个就不好弄了。

    2.sscanf只能处理最标准的数据,如果每一行格式都一样,可以使用,如果不一样,会遇到很多问题。

    #define _CRT_SECURE_NO_WARNINGS
    #include<stdio.h>
    #include <stdlib.h>
    
    char path[256] = "Z:\I\尹成清华终极版C语言视频源码文档20150131\大数据相关数据\批量级别NASA.txt";
    
     typedef struct haihualove
    {
        char allstr[2048];
        int id;
        char name[10];
        char sex[3];
        int age;
        int tall;
        char study[10];
        char mary[10];
        char where[10];
    }H,*PH;
     PH ph;
     void init()
     {
          ph = calloc(100, sizeof(H));//开辟空间
         //127740    1小姐    女    22    166    本科    未婚    合肥    山羊座    编辑    普通话    安徽,浙江,江苏,上海    面议元/天    初次接触    商务伴游,私人伴游,交友伴游,景点伴游    本人今年22岁,半年前大学毕业,平时在上海工作,放假时回安徽。有意可以联系我哦。另外我是大叔控。。。    0:00—23:00    15755106787    1718560307@qq.com    http://www.banyou.com/    1718560307
    
         FILE *pf = fopen(path, "r");
         for (int i = 0; i < 101; i++)
         {
             char str[2048] = { 0 };
             fgets(str, 2048, pf);
             if (i >= 1)
             {
    
                
                
                 strcpy(ph[i - 1].allstr, str);//拷贝总串
                 sscanf(str, "%d %s %s %d %d %s %s %s", &ph[i - 1].id, ph[i - 1].name, ph[i - 1].sex, &ph[i - 1].age, &ph[i - 1].tall, ph[i - 1].study, ph[i - 1].mary, ph[i - 1].where);
    
             }
         }
    
         fclose(pf);
     }
    
    
     void main()
     {
         init();
    
         for (int i = 0; i < 100;i++)
         {
             if (strcmp(ph[i].mary,"已婚")==0)
             {
                 printf("%s
    ", ph[i].allstr);
             }
            /* if (ph[i].age<20 && ph[i].tall>165)
             {
                 printf("%s
    ", ph[i].allstr);
             }*/
         }
    
    
    
    
        
         system("pause");
     }
    
    void main1()
    {
        FILE *pf = fopen(path, "r");
        while (!feof(pf))
        {
            char str[2048] = { 0 };
            fgets(str, 2048, pf);
            printf("%s", str);
            printf("
    
    
    
    ");
    
        }
        fclose(pf);
    
    
        system("pause");
    }
  • 相关阅读:
    ssh图示+hibernate图示
    spring Transactional
    Spring datasource
    sqlloader导入数据
    Spring Aop Annotation(@Pointcut)
    ajax传输文件+检验
    Spring Aop Annotation
    JDK的动态代理
    nginx代理gitlab
    python相关
  • 原文地址:https://www.cnblogs.com/sjxbg/p/5892301.html
Copyright © 2011-2022 走看看