Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- int getSum(char *array[], int n);
- int getSump(char **array, int n);
- int main(int argc, char *argv[]){
- int i;
- if (argc < 2){
- printf("too few arguments!\n");
- exit(1);
- } else{
- for (i = 1; i < argc; i++){
- if (**(argv + i) = ' '){
- **(argv + i) = '+';
- }
- }
- printf("%d arguments excluding \"a.out\": \n", argc);
- printf("%s\n", *argv);
- printf("= %d\n", getSum(argv, argc));
- printf("= %d\n", getSum(argv, argc));
- }
- }
- int getSump(char **array, int n){
- int sum = 0;
- int i;
- for (int i = 0; i < n; i++){
- if (**(array+ i) >= '0' && **(array+ i) <= '9'){
- sum += **(array+ i);
- }
- }
- return sum;
- }
- int getSum(char *array[], int n){
- int sum = 0;
- int i;
- for (int i = 0; i < n; i++){
- if (**(array+ i) >= '0' && **(array+ i) <= '9'){
- sum += **(array+ i);
- }
- }
- return sum;
- }
- // char *input[80];
- // int i,j, counter = 0;
- // fgets(*input, 90, stdin);
- // printf("%s", *input);
- // // while (input[0][i] != '\n'){
- // // if(input[0][i] == ' '){
- // // input[0][i] == '+';
- // // }
- // // if(input[0][i] >= '0' && input[0][i] <= '9'){
- // // counter++;
- // // }
- // // i++;
- // // }
- // // printf("%s", *(input+0));
- // // for(j = 0; j < sizeof(*input); j++){
- // // if (*(input + j) == " "){
- // // *(input + j) = " + ";
- // // }
- // // if (**(input + j) >= '0' && **(input + j) <= '9'){
- // // counter++;
- // // }
- // // }
- // // printf("%c", userInput);
- // // *input = "s";
- // // printf("%s", *input);
- // // printf("%s", userInput);
- // // while (*(userInput + i) != '\n'){
- // // printf("%s", userInput);
- // // i++;
- // // sscanf()
- // // **(input + i) = userInput;
- // // i++;
- // // scanf("%c", &userInput);
- // // }
- // // printf("%s", *input);
- // // for(j = 0; j < sizeof(input); j++){
- // // if (*(input + j) == " "){
- // // *(input + j) = " + ";
- // // }
- // // if (**(input + j) >= '0' && **(input + j) <= '9'){
- // // counter++;
- // // }
- // // }
- // // printf("%d arguments excluding \"a.out\"\n", counter);
- // // printf("%s\n", *input);
- // // printf("= %d", getSum(input, sizeof(input)));
- // // printf("= %d", getSump(input, sizeof(input)));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement