So I am still struggling to get my Caesar program to read argv1[1]. my program compiles and returns a value of "1" if the incorrect number of arguments are entered. The problem seems to be that it is not reading argv[1] at all. I feel like i have set up a function that should look at every index in argv[1] to determine if they are decimals or not. BUT, it appears that this is not happening.
The evidence is that I am not returning the "Usage: key" message when i enter to many arguments at the command line. Also, no matter what I enter whether it is "2" or "2blab" i still get prompted to enter "plaintext".
my code might look cluttered with comments but I tried to comment every area to show my thinking. Can someone help me out?
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <stdbool.h>
//function that takes in argv[1], reads it, and determines if it meets criteria
//criteria defined as only decimal digits between 0 and 9. letters etc are not accepted.
int verifyinput(string b);
int main (int argc, string argv[])
{
//if correct number of arguments are entered check argv[1] for compliance with entry critera.
if (argc==2)
{
//sends argv[1] to verify its contents
//returns an integer that is the size of the number of acceptable digits
int verify = verifyinput(argv[1]);
//if the number of acceptable digits is different then the length of argv[1]
//the user is given the following error message and the program ends
if (verify != strlen(argv[1]))
{
printf("Usage: ./caesar key \n");
}
//if the number of acceptable digits is the same as the length of the argv[1]
//the user is prompted to enter text to encipher
else if (verify == strlen(argv[1]))
{
string k = get_string("PlainText: ");
}
}
//if user arguments are not entered correctly
//error message 1 is displayed
if (argc!=2)
{
printf("1 \n");
}
}
int verifyinput(string b)
{
int length = strlen(b);
int check = 0;
// loop that reads each digit of string b
for (int i = 0; i<=length; i++)
{
//ascii code for zero through nine are 0 through 9. any digit larger then ascii 9 is outside accepted range
//check is added to in the event that b[i] is less then or equal to 9
if (b[i]<=9)
{
check++;
}
//check is subtracted from if b[i] is greater then 9
if (b[i]>9)
{
check--;
}
}
//returns value to int verify in main
return check;
}