I have a structure array is as following:
struct contact {
char *name;
char *phone;
char *address;
}contactList[1024];
My question asked for me about how to add content to structure array from the function of addContact
The parameters for this fuction are as following:
addContact(char* name, char* phone, char* address)
My problem is I can add the content to structure array, but only the contact record in array[0], even I have add the pointer for jumping to next row
The function I wrote as following:
void addContact(char* name, char* phone, char* address) {
int i;
struct contactList *ptr=contactList;
for (i=0; i<4; i++) {
ptr[i].name=name;
ptr[i].phone=phone;
ptr[i].address=address;
*ptr++;
contactCount++;
}
Another problem is I can only get the value in array[0]( total 1 record can be returned), and even added the pointer here for jumping to next row
The function I wrote as following:
char* getPhoneOfName(char* name) {
int i;
struct contactList *ptr=contactList;
for (i=0; i<3; i++){
if (ptr->name==name){
return ptr->phone;
*ptr++; }
else return NULL;
}
}
in the main()
There are the data to be added to structure array using the function addContact
addContact("Bendy", "10836588", "22 Tai Cheung Street, Tai Ko");
addContact("May", "55769943", "59 Hai Tong Road, Aberdeen");
addContact("June", "10599813", "1C Fung Yee Street, Wan Chai");
printf("getPhoneOfName = %s\n", getPhoneOfName("Bendy"));
printf("getPhoneOfName = %s\n", getPhoneOfName("May"));
printf("getPhoneOfName = %s\n", getPhoneOfName("June"));
plz help!!
THX!!
Ps. the value array[0] means the value in addContact("June", "10599813", "1C Fung Yee Street, Wan Chai") can be added to structure array and can be read from the function printf("getPhoneOfName = %s\n", getPhoneOfName("June")) the phone number 10599813 will be returned;