标题:奇怪 怎么分开读取,
只看楼主
xcduwenge
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-6-23
 问题点数:0 回复次数:1 
奇怪 怎么分开读取,
#include <stdio.h>
#include <string.h>
#define SIZE 15
#define NUM 60

struct ip_net
{
    char IP[SIZE];
    char NET[SIZE];
}network[NUM];

void main()
{
 
    FILE *fp;
    int i;
 
    fp=fopen("d:\\duwenge.txt","r");
        for(i=0;i<NUM;i++)
        {
             fread(&network[i],sizeof(struct ip_net),1,fp);
             printf("%s",network[i].IP,network[i].NET); /*为什么一个%s就够了*/
        }
    fclose(fp);
    fp=fopen("d:\\duwenge.txt","r");
    int j,index;
    index=0;
    int k;
    for(i=0;i<NUM;i++)
    {
        for(j=i+1;j<NUM;j++)
        {
            
            for(k=0;k<SIZE;k++)
                if(network[i].IP[k]==network[j].IP[k]&&network[i].IP[k]!=' '
                    &&network[j].IP[k]!=' ')
                {};/*怎么分开读取*/
            
                break;
                
        }
        if(j==NUM)
            index++;
    }  
    printf("The number of ip is %d\n",index);
    fclose(fp);
   
}

文件内容为
219.139.140.2    baidu.com
219.139.140.2    baidu.com
219.139.140.1    baidu.com
219.139.140.2    baidu.com
219.139.140.9    baidu.com
219.139.140.7    baidu.com
219.139.140.2    baidu.com
219.139.140.2    
219.139.140.24    
219.139.140.3    
219.139.140.4    
219.139.140.5    
219.139.140.6    
219.139.140.1    
219.139.140.1    
219.139.140.1    
219.139.140.10    
219.139.140.11    
219.139.140.12    
219.139.140.13    
219.139.140.14    
219.139.140.15    
219.139.140.16    
219.139.140.17    
219.139.140.18    
219.139.140.19    
219.139.140.20    
219.139.140.21    
219.139.140.22    
219.139.140.23    
219.139.140.24    baidu.com
219.139.140.25    baidu.com
219.139.140.26    baidu.com
219.139.140.27    baidu.com
219.139.140.28    baidu.com
219.139.140.29    baidu.com
219.139.140.30    baidu.com
219.139.140.31    
219.139.140.32    
219.139.140.33    
219.139.140.34    
219.139.140.35    
219.139.140.36    
219.139.140.37    
219.139.140.38    
219.139.140.39    
219.139.140.40    
219.139.140.41    
219.139.140.42    
219.139.140.43    
219.139.140.44    
219.139.140.45    
219.139.140.46    
219.139.140.46    
219.139.140.46    
219.139.140.46    
219.139.140.51    
219.139.140.51    
219.139.140.51    
219.139.140.51    
搜索更多相关主题的帖子: void network include 
2008-06-25 17:35
lonelinsky
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2008-5-21
得分:0 
支持表意不清……
2008-06-25 20:58



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-221210-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.125636 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved