5) Numeric addresses for computers on the international network Internet are com
ID: 3643645 • Letter: 5
Question
5) Numeric addresses for computers on the international network Internet are composed of four parts, separated by periods, of the form:
xx.yy.zz.mm
where xx, yy, zz, and mm are positive integers. Locally, computers are usually known by a nickname as well. You are designing a program to process a list of Internet addresses, identifying all pairs of computers from the same locality. Create a structure type called address_t with components for the four integers of an Internet address and a fifth component in which to store an associated nickname of 10 characters. Your program should read a list of up to 100 addresses and nicknames terminated by a sentinel address 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 should display a list of messages identifying each pair of computers from the same locality---that is, each pair of computers with matching values in the first two components of the address. In the messages, the computers should be identified by their nicknames.
Explanation / Answer
#include #include #include struct address_t {int xx; int yy; int zz; int mm; char nname[10]; }add[100]; int local_address(struct address_t,struct address_t ); void scan_address(char[],struct address_t[],int); void print_address(struct address_t); int main() {char address[12]; FILE *in; int i=0,j,k; in=fopen("input.txt","r"); if(in == NULL) {printf("Error opening input file! "); return 0; } fscanf(in,"%s",&address); while(strcmp(address,"0.0.0.0")!=0) {fscanf(in,"%s",add[i].nname); scan_address(address,add,i); i++; fscanf(in,"%s",&address); } printf("the addresses are: "); for(j=0;jRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.