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

Will Rate Fullest & Please Program in C Only. Not C++ Problem: Numeric addresses

ID: 3610987 • Letter: W

Question

Will Rate Fullest & Please Program in C Only. Not C++


Problem:

Numeric addresses for computers on the international networkInternet are composed of four parts, separated by periods, of theform

xx.yy.zz.mm

where xx, yy, zz, and mm are positive integers. Locally, computersare usually known by a nickname as well. you are designing aprogram to process a list of Internet addresses, identifying allpairs of computers from the same locality. Create a structure typecalled address_t with components for the four integers of anInternet address and a fifth component in which to store anassociated nickname of 10 characters. Your program should read alist of up to 100 addresses and nicknames terminated by a sentineladdress of all zeros and a sentinel nickname.

Sample Data:
111.22.3.44       platte
555.66.7.88       wabash
111.22.5.66       green
0.0.0.0               none

The program shoudl display a list of messages identifying each pairof computers from the same locality - that is, each pair ofcomputers with matching values should be identified by theirnicknames.

Example Message:

Machines platte and green are on the same local network.

Follow the messages by a display of the full list of addresses andnicknames. Include in your program a scan_address function.Function local_address should take two address structures as inputparameters and return 1 (for true) if the addresses are on the samelocal network, and 0 (for false) otherwise.

Thank You

Explanation / Answer

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

#defineNUM_ADDRESSES 100
#define NUM_CHARACTERS 11


struct address_t
{
int xx;
int yy;
int zz;
int mm;
char NickName[NUM_CHARACTERS];
};

void scan_address(structaddress_t *ap)
{
/* Declaring variable i for changing the element of the array*/
int i = 0;

printf("Please enterthe list IP address's followed by there nickname's (xx.yy.zz.mmnickname) ");
printf("To finish entering the list, please insert a sentineladdress and nickname (0.0.0.0 none): ");

do
   {
      /* Scans in the IP address andnickname, and saves them in the structure */

      scanf("%d.%d.%d.%d %s",&ap[i].xx, &ap[i].yy, &ap[i].zz, &ap[i].mm,&ap[i].NickName);
      /* A value of an IP address is notgreater then 250 */
      if ( ap[i].xx > ap[i].yy >ap[i].zz > ap[i].mm > 250 )
      {
         printf("ERROR: Avalue of an IP address is not greater then 250. ");
         exit(-1); /* Exitsprogram if above is true */
      }
      /* The nickname can't be longer then10 characters */
      else if ( (int) sizeofap[i].NickName > 11 )
      {
         printf("ERROR: Thecomputers nickname can't be longer then 10 characters. ");
         exit(-1); /* Exitsprogram if above is true */
      }
      else
         i++;
   } while ( (ap[i].xx != 0 && ap[i].yy != 0&& ap[i].zz!= 0 && ap[i].mm != 0
             && ap[i].NickName != "none") || i <= NUM_ADDRESSES);

int local_address(structaddress_t a[], struct address_t b[])
{
/* Declaring value to return. */
int value;

/* Checks to see ifthe values in the first two components of
    the address are the same, if so return 1, ifnot, return 0 */
if ( a->xx == b->xx && a->yy == b->yy)

  value = 1;
else
  value = 0;

return value;
}

void print_address(structaddress_t a[])
{
/* Declaring variable h for changing the element of the array*/
int h;

/* Prints out thelist of addresses and nicknames */
for (h = 0; h < NUM_ADDRESSES; h++)
  printf("%d.%d.%d.%d %s ", a[h].xx, a[h].yy, a[h].zz,a[h].mm, a[h].NickName);
}

int main(void)
{
/* Declaring an array, a, of type address_t */
struct address_t a[NUM_ADDRESSES];
/* Declaring variable j and k for changing the element of thearray */
/* Declaring variable l for the return value of the functionlocal_address */
int j, k, l;

/* Calling afunction that scans in the data, and saves it in structure a.*/
scan_address(a);

  for (j = 0; j< NUM_ADDRESSES; j++)
           {
  for (k = 0; k < NUM_ADDRESSES; k++)
                 {
   if (j < k)
                       {
    /* Calling a function that takes twoaddress structures
               and checks if they are on the same local network. If
       they are then it returns 1, ifnot returns 0. */
    l = local_address(a[j], a[k]);
    /* If addresses are from the same network,then print message. */
    if (l == 1)
     printf("Machines %s and %s are on thesame local network. ", a[j].NickName, a[k].NickName);
   }
  }
}

  print_address(a);

return 0;
}

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