I did not bother to name this...

From Scribby Mockingbird, 1 Week ago, written in C, viewed 20 times.
URL http://codebin.org/view/1bb7f3a0 Embed
Download Paste or View Raw
  1. #include <cs50.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5.  
  6. int main(int argc, string argv[])
  7. {
  8.     //check if user has entered only one cml argument
  9.     if (argc != 2)
  10.     {
  11.         printf("Usage: caesar <key> (key must be an integer)\n");
  12.         return 1;
  13.     }
  14.     printf("Success!\n%s\n", argv[1]);
  15.     //go over every char of the string  
  16.     int k = 0;
  17.     int i = strlen(argv[1]);
  18.     for (int j = 0; j < i; j++)
  19.     {        
  20.         // if it's a number increase k
  21.         if (isdigit(argv[1][j]) == true)
  22.         {
  23.             printf("digit #%i is a number\n", j);
  24.             k++;
  25.         }
  26.         // if it's not a number, end and complain
  27.         else if (isdigit(argv[1][j]) == false)
  28.         {
  29.             printf("digit #%i is not a number, the key may only contain numbers\n", j);
  30.             return 2;
  31.         }
  32.         else
  33.         {
  34.             // If you want to be contrarian
  35.             return 3;
  36.         }
  37.     }
  38.     if (i != k)
  39.     {
  40.         printf("The key was not entirely numeric\n");
  41.     }
  42.    
  43.     else
  44. }
  45.  

Reply to "I did not bother to name this..."

Here you can reply to the paste above