/** file:main.c* author:liutingting*/#include<stdio.h>#include<stdlib.h>#include<Winsock2.h>#include<string.h>#include<time.h>#include<Ws2tcpip.h>#pragmaComment (lib, "Ws2_32.lib")intMainintargcChar**argv) {intI,j;u_long Count=0; U_short Datalen=0;intSzfh=0; U_long Sumlen=0; U_long Qc_sumlen=0;Char*filepath[3];filepath[0]="C:\\users\\administrator\\desktop\\1208test\\open.txt";Charstorefile[]="C:\\users\\administrator\\desktop\\store.txt";Charsip[ -],dip[ -],id[Ten];intip1=0, ip2=0, ip3=0, ip4=0; FILE*fp[3],* out;//can be used to open multiple files continuously for(i=0;i<1; i++){//itoa (i,first,10); while(Fp[i] = fopen (Filepath[i],"R")) ==NULL) {printf ("can't open file \ n"); exit (0);} Remove (storefile); out=fopen (StoreFile,"A +");Charch;Charline[ -]; while(Fgets (line, -, fp[i])! =NULL) {if(Feof (Fp[i])) {//prevent the last line from being read more Break;}Else{sscanf (line,"%s%s%s", Id,sip,dip);//Write Filefprintf ( out,"%s%s%s\n", Id,sip,dip);p rintf ("line=%s\n", line);p rintf ("id=%s sip=%s dip=%s\n", Id,sip,dip);intIpi=0;intK;ip1=0, ip2=0, ip3=0, ip4=0; for(k=0; sip[k]!=' /'; k++){if(sip[k]=='.') {IPI++;Continue;}Switch(IPI) { Case 0: Ip1=ip1*Ten+ (sip[k]- -); Break; Case 1: Ip2=ip2*Ten+ (sip[k]- -); Break; Case 2: IP3=ip3*Ten+ (sip[k]- -); Break; Case 3: IP4=ip4*Ten+ (sip[k]- -); Break; }} printf ("%d %d%d%d\n", IP1,IP2,IP3,IP4);}}} Fclose (fp[0]); Fclose ( out); system ("Pause");returnexit_success;}
Operation Result:
Splits an IP address string into four integer forms