daily pastebin goal
46%
SHARE
TWEET

Untitled

joharido Mar 25th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. int getSum(char *array[], int n);
  5. int getSump(char **array, int n);
  6. int main(){
  7.     char *input[] = {};
  8.     char userInput;
  9.     int i,j, counter = 0;
  10.     while (userInput != EOF){    
  11.         scanf("%c", &userInput);
  12.         **(input + i) = userInput;
  13.         i++;
  14.     }
  15.     for(j = 0; j < sizeof(input); j++){
  16.         if (*(input + j) == " "){
  17.             *(input + j) = " + ";
  18.         }
  19.         if (**(input + j) >= '0' && **(input + j) <= '9'){
  20.             counter++;
  21.         }
  22.     }
  23.     printf("%d arguments excluding \"a.out\"\n", counter);
  24.     printf("%s\n", *input);
  25.     printf("= %d", getSum(input, sizeof(input)));
  26.     printf("= %d", getSump(input, sizeof(input)));
  27.  
  28. }
  29. int getSump(char **array, int n){
  30.     int sum = 0;
  31.     int i;
  32.     for (int i = 0; i < n; i++){
  33.         if (**(array+ i) >= '0' && **(array+ i) <= '9'){
  34.             sum += **(array+ i);
  35.         }
  36.     }
  37.     return sum;
  38. }
  39. int getSum(char *array[], int n){
  40.     int sum = 0;
  41.     int i;
  42.     for (int i = 0; i < n; i++){
  43.         if (**(array+ i) >= '0' && **(array+ i) <= '9'){
  44.             sum += **(array+ i);
  45.         }
  46.     }
  47.     return sum;
  48. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top