#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char c;
int ip1, ip2, ip3, ip4 ;
char data[256];
char operation[256];
char page[256];
char nomefile1[]="t2.log";
char nomefile2[]="84_11_41_177.txt";
FILE * Fp1;
FILE * Fp2;
Fp1 = fopen(nomefile1, "r");
if (Fp1==NULL){
printf("File %s not found\n", nomefile1);
exit(-1);
}
Fp2 = fopen(nomefile2, "w");
if (Fp2==NULL){
printf("File %s not found\n", nomefile2);
exit(-1);
}
fprintf(Fp2, "Pagine navigate dall'utente 84.11.41.177\n");
while ( fscanf(Fp1, "%d.", &ip1 ) > 0 )
{
fscanf(Fp1, "%d.%d.%d", &ip2, &ip3, &ip4 );
fscanf(Fp1, " - - [%s +0200] %s", data , operation);
fscanf(Fp1, " %s HTTP/1.1", page);
if (ip1 == 84 && ip2 ==11 && ip3== 41 && ip4 ==177)
{
fprintf(Fp2, "%s +0200 ", data );
fprintf(Fp2, "pagina: %s \n", page );
}
while ( fscanf(Fp1, "%c", &c ) > 0 )
{
if (c == '\n' ) break;
}
printf( " \n\n\n" );
}
fflush(stdin);
fflush(Fp1);
fclose (Fp1);
fflush(Fp2);
fclose (Fp2);
return 0;
}