Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Locally, computers are often known by an alias (nickname) as well. You will desi

ID: 3917937 • Letter: L

Question

Locally, computers are often known by an alias (nickname) as well. You will design and write a program to process a list of internet addresses from file "C$222_Inet.txt. Your program should read a list of up to 100 addresses and nicknames terminated by a sentinel address of all zeros and the sentinel nickname, "none". Sample CS222 Inet.txt 11122.3.44 platte 131.250.95.21 jet 172.66.788 wabash 111.22.5.66 green 131.250.47.63 baker 0.0.0.0 none For this assignment, you will create your own test data files using the sample format. Grading will involve using different data files with the same Your program will generate a report listing all computers from the same locality--that is, each computer with matching values in the first two components of the address. In the list, the computers should be identified by their alias. The report will be saved to file "222 Locality Report.The user will also generate a report listing all of the computers sorted alphabetically by alias. This report will be saved to file "222 Alias List. As wwith HW3, both reports will comtain the user's name and current date, along with the generated report listing. Examples: Hal Greenwald July 17,2018 Hal Greenwald July 17, 2018 CS222 Network Alias Listing CS222 Network Locality Repart 111.22 platte green baker green jet platte wabash 131 2504763 111.22.5.66 131.2509521 111.22344 172.66.7.88 131.250 jet baker 172.66 wabash

Explanation / Answer

here is your program : p------------->>>>>>>>>>

#include<stdio.h>
#include<string.h>
#include<time.h>
#include<stdlib.h>


typedef struct Adress{
int p1;
int p2;
int p3;
int p4;
char alias[10];
}address_t;

address_t* read_data_file(int *count){
FILE *fp;
fp = fopen("CS222_Inet.txt","r");
if(fp == NULL){
  printf("Check The CS222_Inet.txt File.Opening Error!!!");
  exit(-1);
}
address_t *temp = (address_t *)malloc(sizeof(address_t)*100);
char line[100];
char alias[10];
*count = 0;
char *word;
while(!feof(fp)){
  fscanf(fp,"%s%s",&line,&alias);
  if(feof(fp)){
   break;
  }
  if(strcmp(line,"0.0.0.0") == 0 && strcmp(alias,"none") == 0){
   break;
  }
  strcpy(temp[*count].alias,alias);
  word = strtok(line,".");
  if(word != NULL){
   temp[*count].p1 = atoi(word);
  }
  word = strtok(NULL,".");
  if(word != NULL){
   temp[*count].p2 = atoi(word);
  }
  word = strtok(NULL,".");
  if(word != NULL){
   temp[*count].p3 = atoi(word);
  }
  word = strtok(NULL,".");
  if(word != NULL){
   temp[*count].p4 = atoi(word);
  }
  *count = *count + 1;
}
fclose(fp);
return temp;
}

int get_unique_loaclity(int locality_t[100][2],address_t *data,int count){
int i,j,c=0;
int p1,p2;
int st;
for(i=0;i<count;i++){
  p1 = data[i].p1;
  p2 = data[i].p2;
  st = 0;
  for(j = 0;j<c;j++){
   if(locality_t[j][0] == p1 && locality_t[j][1] == p2){
    st = 1;
    break;
   }
  }
  if(st == 0){
   locality_t[c][0] = p1;
   locality_t[c][1] = p2;
   c++;
  }
}

return c;
}

void generate_locality_report(address_t *data,int count,int locality_t[100][2],int lcount,char *user){
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
FILE *fp;
fp = fopen("CS222_locality_report.txt","w");
if(fp == NULL){
  printf("File Opening Error!!!");
  exit(-1);
}
fprintf(fp,"%s %s",user,asctime(timeinfo));
fprintf(fp,"%s","CS222 Network Locality Report");
int i,j;
for(i = 0;i<lcount;i++){
  fprintf(fp," %d.%d ",locality_t[i][0],locality_t[i][1]);
  for(j = 0;j<count;j++){
   if(data[j].p1 == locality_t[i][0] && data[j].p2 == locality_t[i][1]){
    fprintf(fp," %s",data[j].alias);
   }
  }
}
printf("File CS222_locality_report.txt is written check output !!! ");
fclose(fp);
}

void swap(address_t *data1,address_t *data2){
address_t temp;
strcpy(temp.alias,data1->alias);
temp.p1 = data1->p1;
temp.p2 = data1->p2;
temp.p3 = data1->p3;
temp.p4 = data1->p4;
data1->p1 = data2->p1;
data1->p2 = data2->p2;
data1->p3 = data2->p3;
data1->p4 = data2->p4;
strcpy(data1->alias,data2->alias);
data2->p1 = temp.p1;
data2->p2 = temp.p2;
data2->p3 = temp.p3;
data2->p4 = temp.p4;
strcpy(data2->alias,temp.alias);
}

void sortByAlias(address_t *data,int count){
int i,j;
for(i=0;i<count;i++){
  for(j = i+1;j<count;j++){
   if(strcmp(data[i].alias,data[j].alias) > 0){
    swap(&data[i],&data[j]);
   }
  }
}
}

void generate_alias_list(address_t *data,int count,char *user){
sortByAlias(data,count);
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
FILE *fp;
fp = fopen("CS222_alias_list.txt","w");
if(fp == NULL){
  printf("File Opening Error!!!");
  exit(-1);
}
fprintf(fp,"%s %s",user,asctime(timeinfo));
fprintf(fp,"%s ","CS222 Network Alias Listing");
int i;
for(i = 0;i<count;i++){
  fprintf(fp," %s %d.%d.%d.%d",data[i].alias,data[i].p1,data[i].p2,data[i].p3,data[i].p4);
}
printf(" File CS222_alias_list.txt is written check output !!! ");
fclose(fp);
}

int main(){
address_t *datas;
int count = 0;
int locality_t[100][2];
int lcount;
char *user = (char *)malloc(sizeof(char)*100);
printf(" Enter User Name : ");
fgets(user,100,stdin);
user[strlen(user)-1] = '';
datas = read_data_file(&count);
lcount = get_unique_loaclity(locality_t,datas,count);
generate_locality_report(datas,count,locality_t,lcount,user);
generate_alias_list(datas,count,user);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote