奇怪 怎么分开读取,
#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