Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. Contact* addContact(Contact *myContacts, char *contactName) {
  2. if (contactName != NULL) {
  3. printf("Error this contact already exists");
  4. return myContact;
  5. }
  6. Contact *newNode = malloc( sizeof(Contact) );
  7. newNode->name = malloc( strlen(contactName) + 1 );
  8. strcpy(newNode->name, contactName);
  9. newNode->next = myContacts;
  10. return newNode;
  11. }
  12.  
  13.  
  14. /////////////////////////////////////////////////////////////////////////////////////////////
  15. // adds a new piece of inforamtion to the specified contact
  16. // 1. Make sure a contact by that name exists (so you can add information to it)
  17. // 2. If the informational item already exists, update the information's value to the new value
  18. // 3. Otherwise, add the piece of information to the end of the contact's information list (add-at-end)
  19.  
  20. void addInformation(Contact *myContacts, char *contactName, char *infoName, char *infoValue) {
  21. // check to see if contact exists
  22. if (contactName matches ) { // fix if statement
  23. Contact *newNode = malloc( sizeof(Contact) );
  24. Info *2ndNode = malloc( sizeof(Info) );
  25. newNode->name = malloc( strlen(contactName) + 1 );
  26. strcpy(2ndNode->name, infoName);
  27. strcpy(2ndNode->infoName, infoValue);
  28. strcpy(newNode->name, contactName);
  29. newNode->information = infoName;
  30. newNode->next = NULL;
  31. if (myContacts == NULL) {
  32. return newNode;
  33. }
  34. Contact *temp = myContacts;
  35. while (temp->next != NULL) {
  36. temp = temp->next;
  37. }
  38. temp->next = newNode;
  39. }
  40. return;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement