Guest User

Untitled

a guest
Apr 12th, 2020
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cs50.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5. #include <math.h>
  6. #include <stdlib.h>
  7.  
  8.  
  9.  
  10. int main(int argc, string argv[])
  11. {
  12.  
  13.     //Check the command line for 2 line arguments
  14.     if (argc != 2)
  15.     {
  16.     printf("ERROR: Enter one key on command-line\n");
  17.     return 1;
  18.     }
  19.    
  20.  
  21.  
  22.    // Put argv into an integer (k).
  23.     int k = atoi(argv[1]);
  24.     if (k < 0)
  25.     {
  26.         printf("Enter a positive value\n");
  27.         return 1;
  28.     }
  29.  
  30.    // Check if (k) is only digits.
  31.  
  32.     for(int i = 0; i < strlen(argv[1]); i++)
  33.         if(isalpha(argv[1][i]))
  34.         {
  35.             printf("Usage: ./caesar key\n");
  36.             return 1;
  37.         }
  38.  
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment