← cproj

return integers instead of using void function

2c30dee48c0e72b6b16b0cdb120f7ffec203ca23 · ovidiucs · Dec 2, 2019 17:17

+10 −4 · 1 file changed

  • graph/db/codevault/ret_multiple_values_from_func.c +10 −4
diff --git a/graph/db/codevault/ret_multiple_values_from_func.c b/graph/db/codevault/ret_multiple_values_from_func.c
index 1775061..a1fa8fd 100644
--- a/graph/db/codevault/ret_multiple_values_from_func.c
+++ b/graph/db/codevault/ret_multiple_values_from_func.c
@@ -1,7 +1,10 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-void sumAndProduct(int a, int b, int* sum, int* prod){
+int sumAndProduct(int a, int b, int* sum, int* prod){
+  if (sum == NULL || prod == NULL){
+    return(0);
+  }
   *sum = a + b;
   *prod = a * b;
 }
@@ -10,10 +13,13 @@ void sumAndProduct(int a, int b, int* sum, int* prod){
 int main (int argc, char** argv) {
     int x = 5;
     int y = 12;
-    int sum = 0
+    int sum = 0;
     int prod = 0;
-    sumAndProduct(x, y, &sum, &prod);
+    int status = sumAndProduct(x, y, &sum, &prod);
+    if (!status) {
+      fprintf(stderr, "Something went wrong\n");
+    } else {
     fprintf(stdout,"The sum is %d and the product is %d\n", sum, prod);
-
+    }
    return EXIT_SUCCESS;
 }