Question: #include #include #include #include #include // Global Vars for fileChNames char InputFile[] = CS222_Inet.txt; char Output_Locality_Rpt[] = 222 Locality Report.txt; char Output_Alias_List[] = 222 Alias
#include
// Global Vars for fileChNames char InputFile[] = "CS222_Inet.txt"; char Output_Locality_Rpt[] = "222 Locality Report.txt"; char Output_Alias_List[] = "222 Alias List.txt";
// structure to hold the first 2 parts in an ip address struct locality_t { int IP1; int IP2; struct locality_t *nxt; };
// structure to hold the data file information struct address_t { int IP1; int IP2; int IP3; int IP4; char ChName[10]; };
int Read_Data_File (struct address_t *);
void BubbleSort (int, struct address_t *);
void Generate_Locality_Rpt (int, struct address_t *);
void Generate_Alias_List (int, struct address_t *);
void Insert_locality_t(struct locality_t **, int , int );
int main () { int i,j;
struct address_t Dfile[100];
int num = Read_Data_File(Dfile); Generate_Locality_Rpt(num,Dfile); Generate_Alias_List(num,Dfile);
}
void Insert_locality_t(struct locality_t **dptrtoL, int IP1, int IP2) {
if(dptrtoL==NULL) {
struct locality_t *temp = malloc(sizeof(struct locality_t)); temp->IP1 = IP1; temp->IP2 = IP2; *dptrtoL = temp; } else {
struct locality_t *sptrtoL = NULL; sptrtoL = *dptrtoL;
while(sptrtoL != NULL) {
if(sptrtoL->IP1 == IP1 && sptrtoL->IP2 == IP2) {
return; }
sptrtoL = sptrtoL->nxt; } struct locality_t *temp = malloc(sizeof(struct locality_t));
temp->IP1 = IP1; temp->IP2 = IP2;
temp->nxt = *dptrtoL;
*dptrtoL = temp;
} }
int Read_Data_File (struct address_t *address) { int num = 0; char line[30];
FILE *fh = fopen(InputFile ,"r"); do { fgets(line,sizeof(line), fh); if (strstr(line, "none") == NULL) { sscanf(line, "%d.%d.%d.%d %s", &address[num].IP1, &address[num].IP2, &address[num].IP3, &address[num].IP4, address[num].ChName); num++; } } while (strstr(line, "none") == NULL); fclose(fh); return num;
} void BubbleSort(int num, struct address_t *address) { int i,j;
for ( i=1; i
void Generate_Locality_Rpt(int num,struct address_t * address) { int i;
struct locality_t *head = NULL;
struct locality_t *sptrtoL = NULL;
for(i=0;i time_t t = time(NULL); struct tm *tm = localtime(&t); char date_str[64]; strftime(date_str, sizeof(date_str), "%B %d, %Y", tm); fprintf(fh,"RANDOM NAME %s ",date_str); fprintf(fh, "CS222 Network Locality Report " ); while(sptrtoL != NULL) { fprintf(fh,"%d.%d ",sptrtoL->IP1,sptrtoL->IP2 ); for(i=0;i } fprintf(fh, " " ); sptrtoL = sptrtoL->nxt; } fclose(fh); } void Generate_Alias_List(int num,struct address_t * address) { FILE *fh = fopen(Output_Alias_List ,"w"); int i; time_t t = time(NULL); struct tm *tm = localtime(&t); char date_str[64]; strftime(date_str, sizeof(date_str), "%B %d, %Y", tm); fprintf(fh,"Random NAME %s ",date_str); fprintf(fh, "CS222 Network Alias Report " ); BubbleSort(num, address); for(i=0;i } THIS IS MY CODE. COULD YOU PLEASE CHECK IF THE CODE GIVES THE SAME OUT AN MEETS THE BELOW CODNTION. CODE IS IN C LANYGUAGE 
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
