Advertisement
Neinhalt

isdigit bool

Mar 9th, 2022 (edited)
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. #include <cs50.h>
  2. #include <stdio.h>
  3. #include <ctype.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6.  
  7. bool only_digits(string s);
  8.  
  9. int main(int argc, string argv[])
  10. {
  11.     if (argc != 2)
  12.     {
  13.         printf("Usage: argc != 2\n");
  14.         return 1;
  15.     }
  16.     bool check_key = only_digits(argv[1]);
  17.     if (check_key != true)
  18.     {
  19.         printf("Invalid key\n");
  20.         return 1;
  21.     }
  22.     return 0;
  23. }
  24.  
  25. bool only_digits(string s)
  26. {
  27.     for (int i = 0; i < strlen(s); i++)
  28.     {
  29.         if (isdigit(s[i]))
  30.         {
  31.             return s;
  32.         }
  33.         else if (isdigit(s[i]) == 0)
  34.         {
  35.             return false;
  36.         }
  37.     }
  38.     return s;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement