So, in Caesar when validating the key they asked to check if all the characters in the command line argument provided are digits and only printout "Success" and the digits as an integer if all the chars in the argument are digits.
But when I run my program instead of printing out this:
it prints out this:
It prints out everything twice.
Here is my code. Please help as best you can as I´ve spent a lot of time on this and can't solve the issue.
Thanks :)
#include <ctype.h>
#include <cs50.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main(int argc, string argv[])
{
if (argc == 2 )
{
string arg = argv[1];
for (int i = 0, n = strlen(arg); i < n; i++)
{
if (isdigit(arg[i]))
{
int key = atoi(arg);
printf ("Sucess\n%i\n", key);
}
else
{
printf ("Usage: ./caesar key\n");
}
}
}
else
{
printf ("Usage: ./caesar key\n");
}
}