Advertisement
joharido

Untitled

Mar 25th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.71 KB | None | 0 0
  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(int argc, char *argv[]){
  7.     int i;
  8.     if (argc < 2){
  9.         printf("too few arguments!\n");
  10.         exit(1);
  11.     } else{
  12.         for (i = 1; i < argc; i++){
  13.             if (**(argv + i) = ' '){
  14.                 **(argv + i) = '+';
  15.             }
  16.         }
  17.         printf("%d arguments excluding \"a.out\": \n", argc);
  18.         printf("%s\n", *argv);
  19.         printf("= %d\n", getSum(argv, argc));
  20.         printf("= %d\n", getSum(argv, argc));
  21.     }
  22. }
  23.  
  24. int getSump(char **array, int n){
  25.     int sum = 0;
  26.     int i;
  27.     for (int i = 0; i < n; i++){
  28.         if (**(array+ i) >= '0' && **(array+ i) <= '9'){
  29.             sum += **(array+ i);
  30.         }
  31.     }
  32.     return sum;
  33. }
  34. int getSum(char *array[], int n){
  35.     int sum = 0;
  36.     int i;
  37.     for (int i = 0; i < n; i++){
  38.         if (**(array+ i) >= '0' && **(array+ i) <= '9'){
  39.             sum += **(array+ i);
  40.         }
  41.     }
  42.     return sum;
  43. }
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.     // char *input[80];
  59.     // int i,j, counter = 0;
  60.     // fgets(*input, 90, stdin);
  61.     // printf("%s", *input);
  62.     // // while (input[0][i] != '\n'){
  63.     // //     if(input[0][i] == ' '){
  64.     // //         input[0][i] == '+';
  65.     // //     }
  66.     // //     if(input[0][i] >= '0' && input[0][i] <= '9'){
  67.     // //         counter++;
  68.     // //     }
  69.     // //     i++;
  70.     // // }
  71.     // // printf("%s", *(input+0));
  72.  
  73.  
  74.  
  75.  
  76.  
  77.    
  78.     // // for(j = 0; j < sizeof(*input); j++){
  79.     // //      if (*(input + j) == " "){
  80.     // //          *(input + j) = " + ";
  81.     // //      }
  82.     // //      if (**(input + j) >= '0' && **(input + j) <= '9'){
  83.     // //          counter++;
  84.     // //      }
  85.     // //  }
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.     // //  printf("%c", userInput);
  98.     // //  *input = "s";
  99.     // //  printf("%s", *input);
  100.     // // printf("%s", userInput);
  101.     // // while (*(userInput + i) != '\n'){  
  102.     // //     printf("%s", userInput);
  103.     // //     i++;
  104.     // //     sscanf()
  105.        
  106.        
  107.        
  108.        
  109.     // //     **(input + i) = userInput;
  110.     // //      i++;
  111.     // //      scanf("%c", &userInput);
  112.     // //  }
  113.     // //  printf("%s", *input);
  114.     // // for(j = 0; j < sizeof(input); j++){
  115.     // //     if (*(input + j) == " "){
  116.     // //         *(input + j) = " + ";
  117.     // //     }
  118.     // //     if (**(input + j) >= '0' && **(input + j) <= '9'){
  119.     // //         counter++;
  120.     // //     }
  121.     // // }
  122.     // // printf("%d arguments excluding \"a.out\"\n", counter);
  123.     // // printf("%s\n", *input);
  124.     // // printf("= %d", getSum(input, sizeof(input)));
  125.     // // printf("= %d", getSump(input, sizeof(input)));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement