标签:
/* * File: main.c * Author: liutingting */ #include<stdio.h> #include<stdlib.h> #include<Winsock2.h> #include<string.h> #include<time.h> #include <Ws2tcpip.h> #pragma comment(lib,"WS2_32.lib") int main(int argc, char** argv) { int i,j; u_long count=0; u_short datalen=0; int SZFH=0; u_long sumlen=0; u_long qc_sumlen=0; char *filePath[3]; filePath[0]="C:\\Users\\Administrator\\Desktop\\1208test\\open.txt"; char storefile[]="C:\\Users\\Administrator\\Desktop\\store.txt"; char sip[20],dip[20],id[10]; int ip1=0,ip2=0,ip3=0,ip4=0; FILE *fp[3],*out; //可用于连续打开多个文件 for(i=0;i<1;i++) { //itoa(i,first,10); while ((fp[i] = fopen(filePath[i], "r")) == NULL) { printf("无法打开文件\n"); exit(0); } remove(storefile); out=fopen(storefile,"a+"); char ch; char line[100]; while (fgets(line, 100, fp[i])!=NULL) { if(feof( fp[i])){//防止最后一行多读 break; } else { sscanf(line,"%s%s%s",id,sip,dip); //写入文件 fprintf(out,"%s %s %s\n",id,sip,dip); printf("line=%s\n",line); printf("id=%s sip=%s dip=%s\n",id,sip,dip); int ipi=0; int k; ip1=0,ip2=0,ip3=0,ip4=0; for(k=0;sip[k]!=‘\0‘;k++) { if(sip[k]==‘.‘) { ipi++; continue; } switch(ipi) { case 0: ip1=ip1*10+(sip[k]-48); break; case 1: ip2=ip2*10+(sip[k]-48); break; case 2: ip3=ip3*10+(sip[k]-48); break; case 3: ip4=ip4*10+(sip[k]-48); break; } } printf("%d %d %d %d\n",ip1,ip2,ip3,ip4); } } } fclose(fp[0]); fclose(out); system("pause"); return EXIT_SUCCESS; }
运行结果示意:
标签:
原文地址:http://www.cnblogs.com/tingting-0919/p/5054983.html