im having some problems with my code. after the code is a list of the errors i got. could someone please help. The lines that im having trouble with are:
if (a[].xx == b[].xx && a[].yy == b[].yy) <- in local_address
l = local_address(a[j], a[k]); <- in main
ERRORSCode:/***************************************************************\ * * This program processes a list of internet addresses, * identifying all pairs of computers from the same locality * Each IP address is inputted with an associated nickname. * eg (192.753.0.4 green). * * Up to 100 addresses and nicknames can be inputted, the * nickname can be up to 10 characters in length, the list * can be terminated by a sentinel address and sentinel * nickname (0.0.0.0 none). * * The program displays a list of messages identifying each * pair of computers form the same locality, that is, each * pair o computers with matching values in the first two * components of the address. Following the messages is the * full list of addresses and nicknames. * * * BY ANDREW WILKINSON (13380698) * \***************************************************************/ #include <stdio.h> #include <stdlib.h> /* Declares exit() */ #define NUM_ADDRESSES 100 /* Max size of the number of IP address's */ #define NUM_CHARACTERS 11 /* Max number of characters for the nickname */ /* Defining a structure type called address_t that has 4 members for the IP address values, and 1 member for the computers nickname. */ struct address_t { int xx; int yy; int zz; int mm; char NickName[NUM_CHARACTERS]; }; void scan_address(struct address_t *ap[]) { /* Declaring variable i for changing the element of the array */ int i = 0; printf("Please enter the list IP address's followed by there nickname's (xx.yy.zz.mm nickname)\n"); printf("To finish entering the list, please insert a sentinel address and nickname (0.0.0.0 none):\n"); /* Reading in a list of up to 100 addresses and there nicknames, and being terminated by a sentinel address of all zeros and a sentinel nickname of none. */ do { /* Scans in the IP address and nickname, 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 not greater then 250 */ if (ap[i]->xx > ap[i]->yy > ap[i]->zz > ap[i]->mm > 250) { printf("ERROR: A value of an IP address is not greater then 250.\n"); exit(-1); /* Exits program if above is true */ } /* The nickname can't be longer then 10 characters */ else if ((int) sizeof ap[i]->NickName > 11) { printf("ERROR: The computers nickname can't be longer then 10 characters.\n"); exit(-1); /* Exits program 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(struct address_t a[], struct address_t b[]) { /* Declaring value to return. */ int value; /* Checks to see if the values in the first two components of the address are the same, if so return 1, if not, return 0 */ if (a[].xx == b[].xx && a[].yy == b[].yy) value = 1; else value = 0; return value; } void print_address(struct address_t a[]) { /* Declaring variable h for changing the element of the array */ int h; /* Prints out the list of addresses and nicknames */ for (h = 0; h < NUM_ADDRESSES; h++) printf("%d.%d.%d.%d %s\n", 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 the array */ /* Declaring variable l for the return value of the function local_address */ int j, k, l; /* Calling a function that scans in the data, and saves it in structure a. */ scan_address(&a); /* Creating a loop to input values into the function local_address so they can be tested to see if they are from the same network. */ for (j = 0; j < NUM_ADDRESSES; j++) { for (k = 0; k < NUM_ADDRESSES; k++) { if (j < k) { /* Calling a function that takes two address structures and checks if they are on the same local network. If they are then it returns 1, if not 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 the same local network.\n", a[j].NickName, a[k].NickName); } } } /* Calling a function that prints out the names of the computers that are on the same local network, and then prints out all the list of addresses and nicknames. */ print_address(a); return 0;
Wedit output window build: Fri Nov 3 02:39:10 2006
Error "c:\documents and settings\user\my documents\wilko\lcc\assignment.c": 79 illegal expression
Error "c:\documents and settings\user\my documents\wilko\lcc\assignment.c": 79 left operand of . has incompatible type 'int'
Error "c:\documents and settings\user\my documents\wilko\lcc\assignment.c": 79 illegal expression
Error "c:\documents and settings\user\my documents\wilko\lcc\assignment.c": 79 left operand of . has incompatible type 'int'
Error "c:\documents and settings\user\my documents\wilko\lcc\assignment.c": 79 syntax error; found `)' expecting ']'
Error "c:\documents and settings\user\my documents\wilko\lcc\assignment.c": 79 operands of == have illegal types 'int' and 'struct address_t'
Error "c:\documents and settings\user\my documents\wilko\lcc\assignment.c": 79 syntax error; found `)' expecting ']'
Error "c:\documents and settings\user\my documents\wilko\lcc\assignment.c": 79 illegal expression
Error "c:\documents and settings\user\my documents\wilko\lcc\assignment.c": 79 left operand of . has incompatible type 'int'
Error "c:\documents and settings\user\my documents\wilko\lcc\assignment.c": 79 illegal expression
Error "c:\documents and settings\user\my documents\wilko\lcc\assignment.c": 79 left operand of . has incompatible type 'int'
Error "c:\documents and settings\user\my documents\wilko\lcc\assignment.c": 79 syntax error; found `)' expecting ']'
Error "c:\documents and settings\user\my documents\wilko\lcc\assignment.c": 79 operands of == have illegal types 'int' and 'struct address_t'
Error "c:\documents and settings\user\my documents\wilko\lcc\assignment.c": 79 syntax error; found `)' expecting ']'
Error "c:\documents and settings\user\my documents\wilko\lcc\assignment.c": 79 operands of && have illegal types 'struct address_t' and 'struct address_t'
Error "c:\documents and settings\user\my documents\wilko\lcc\assignment.c": 79 operands of != have illegal types 'struct address_t' and 'int'
Error "c:\documents and settings\user\my documents\wilko\lcc\assignment.c": 79 operands of != have illegal types 'struct address_t' and 'int'
Warning "c:\documents and settings\user\my documents\wilko\lcc\assignment.c": 106 assignment of pointer to array 100 of struct address_t to pointer to pointer to struct address_t
Error "c:\documents and settings\user\my documents\wilko\lcc\assignment.c": 116 type error in argument 1 to `local_address'; found 'struct address_t' expected 'pointer to struct address_t'
Error "c:\documents and settings\user\my documents\wilko\lcc\assignment.c": 116 type error in argument 2 to `local_address'; found 'struct address_t' expected 'pointer to struct address_t'
Compilation + link time:0.2 sec, Return code: 1