Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Contact* addContact(Contact *myContacts, char *contactName) {
- if (contactName != NULL) {
- printf("Error this contact already exists");
- return myContact;
- }
- Contact *newNode = malloc( sizeof(Contact) );
- newNode->name = malloc( strlen(contactName) + 1 );
- strcpy(newNode->name, contactName);
- newNode->next = myContacts;
- return newNode;
- }
- /////////////////////////////////////////////////////////////////////////////////////////////
- // adds a new piece of inforamtion to the specified contact
- // 1. Make sure a contact by that name exists (so you can add information to it)
- // 2. If the informational item already exists, update the information's value to the new value
- // 3. Otherwise, add the piece of information to the end of the contact's information list (add-at-end)
- void addInformation(Contact *myContacts, char *contactName, char *infoName, char *infoValue) {
- // check to see if contact exists
- if (contactName matches ) { // fix if statement
- Contact *newNode = malloc( sizeof(Contact) );
- Info *2ndNode = malloc( sizeof(Info) );
- newNode->name = malloc( strlen(contactName) + 1 );
- strcpy(2ndNode->name, infoName);
- strcpy(2ndNode->infoName, infoValue);
- strcpy(newNode->name, contactName);
- newNode->information = infoName;
- newNode->next = NULL;
- if (myContacts == NULL) {
- return newNode;
- }
- Contact *temp = myContacts;
- while (temp->next != NULL) {
- temp = temp->next;
- }
- temp->next = newNode;
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement