Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of ArraySizeof by
Revision 4:b36f0369c752, committed 2017-11-08
- Comitter:
- CSTritt
- Date:
- Wed Nov 08 12:53:43 2017 +0000
- Parent:
- 3:45a53383e09f
- Commit message:
- Changed (improved) siblings functions.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Nov 08 03:31:24 2017 +0000 +++ b/main.cpp Wed Nov 08 12:53:43 2017 +0000 @@ -2,7 +2,7 @@ Project: StructPlay File: main.cpp Ported to mbed/Nucleo by: Dr. C. S. Tritt - Last revised: 11/7/17 (v. 1.0) + Last revised: 11/7/17 (v. 1.1) Demonstrates various struct usage. All of this code was taken from Horton Chapter 11 and modified. @@ -19,7 +19,7 @@ // Declare the function. bool siblings(Family member1, Family member2); -bool siblingsWP(Family const *pmember1, Family const *pmember2); +bool siblingsWP(Family const *pMember1, Family const *pMember2); int main(void) { @@ -71,16 +71,16 @@ bool siblings(Family member1, Family member2) // Define the function. { - if(strcmp(member1.mother, member2.mother) == 0) - return true; - else - return false; + bool maternal = strcmp(member1.mother, member2.mother); + bool paternal = strcmp(member1.father, member2.father); + return maternal || paternal; } -bool siblingsWP(Family const *pmember1, Family const *pmember2) +// Passing pointers to large structs can save time and memory. +bool siblingsWP(Family const *pMember1, Family const *pMember2) { - if(strcmp(pmember1->mother, pmember2->mother) == 0) - return true; - else - return false; + // const refers to changing field content. + bool maternal = strcmp(pMember1->mother, pMember2->mother); + bool paternal = strcmp(pMember1->father, pMember2->father); + return maternal || paternal; } \ No newline at end of file