Been looking for answers to this, but having a lot of trouble. I am receiving a segfault that seems to be coming from the isdigit line, though I'm not sure what is happening to argv[1] to cause the segfault. I am trying to create a function that goes through each character in argv[1] and returns a bool that says whether they are only digits or not.
#include <cs50.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
bool only_digits(string argv[1]);
int a;
int x;
int main(int argc, string argv[])
{
//verify command line argument
x = strlen(argv[1]);
if (only_digits(&argv[1]) == true || argc != 2)
{
printf ("Usage: caesar key\n");
return 1;
}
//convert argv to int
a = atoi (argv[1]);
//get message
if (only_digits(&argv[1]) == false && argc == 2)
{
string plaintext = get_string("Text: ");
printf("%s\n", plaintext);
}
//rotate message by argv
}
bool only_digits(string argv[1])
{
int b;
for (int i = 0; i < x; i++)
{
b = isdigit(argv[1][i]);
}
return b;
}
The rest of the code for the problem is not done, but I am getting stuck on verifying the the command line argument is only digits.