Charles Tritt / Mbed 2 deprecated StructPlay

Dependencies:   mbed

Fork of ArraySizeof by Charles Tritt

Files at this revision

API Documentation at this revision

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