By Mr. Papadopoulos
Choose your prefered Language: greek_flag uk_flag

The file downloads of an Internet service provider contain the following information for each upload at each line:

  1. IP client address (four integer values, 1-255)
  2. Upload status (0 = successful, 1 = unsuccessful, 2 = hold, positive integer with values ​​of 0,1,2)
  3. File size in Mb (positive number, float)
  4. Transmission volume in Mb

The file is serial, given, and is named IP_clients.txt. Some lines of the file are:


191 255 244 1          0          15.7 15.7

198 168    2 3           2          23.0 16.0

... ...

Each IP address can be more than one time in the file.
Define a structure named log_client to manage this data. The members of the structure will be this information. Then define a table of structures of type log_client, N-places (N = known). The data in the table of structures will be imported by accessing the serial file IP_clients.txt. Assume that the value of N exceeds the number of records in the file. The following are requested (main () function:

  1. Import the data from the IP_clients.txt file into the table of structures by checking the existence of the file (see the code below) according to the above limitation. Find and display the number of lines in the file that the structure table will contain.
  2. Using all elements of the table of structures:
  • Find the total volume and number of downloads in standby
  • Enter a client's IP address from the keyboard without validating values, and then find and display for this client (if present in the table):

The total volume of successful and unsuccessful uploads, i.e. two separate values.

/*Create The File for this Exercise
#include <stdio.h>
#include <stdlib.h>

int main()
    FILE *fp;int n,i,j;


    if (fp==NULL)
        printf("Problem creating file\n");


    for (i=0;i<n;i++)

        for (j=0;j<4;j++)
            fprintf(fp,"%d ",rand()%255+1);
            if (j!=3)
                fprintf(fp," ");
        fprintf(fp,"%d %.2lf %.2lf",rand()%3,(rand()%10+1)*1.0,(rand()%10+1)*1.0);

        if (i!=n-1)