I am trying to iterate over the second command prompt that a user would enter to verify that each character in the array is indeed a digit.
After looking at ASCII, I know, that the characters 0-9
range from 48-57
. I figured out that you could just use isdigit()
but am still wondering why my loop does not work as intended.
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, string argv[])
{
if (argc != 2)
{
printf("Usage: ./caesar key\n");
return 1;
}
for(int i=0, n=strlen(argv[1]); i<n; i++)
{
if((int)argv[1][i] < 48 && (int)argv[1][i] > 57)
{
printf("Usage: ./caesar key\n");
return 1;
}
}
}