0

I keep getting this error:

caesar.c:17:13: error: subscript of pointer to function type 'int (int)' if (isdigit[i] == 0)

This is my code:

#include <cs50.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>

int main (int argc, string argv[])
{
    if (argc != 2)
    {
        printf("Usage: ./caesar key");
    }

    for (int i = 0; i < argc; i++)
    {
        for (int j = 0, n = strlen(argv[i]); j < n; j++)
        {
        if (isdigit[i] == 0)
        {
            printf("Usage: ./caesar key\n");
            return 1;
        }
        else
        {
            printf("Success\n");
            printf("%s\n", argv[1]);
            return 0;
         }
        }  
    }
}


0

That would be isdigit(argv[i][j]), though in this case, i should always be 1 (as only that command-line argument is used for the key).

Also, do not do anything if you find a digit, just keep iterating. After your loop you know that the whole thing is digits-only.

0

in addition to what blauelf posted i believe isdigit returns a values of 0 for integers so if your trying to ensure that only digits are in the command then isdigit(argv[1]) != 0 with whatever printf() and return value you fancy would be the best approach.

Best of luck to you and i hope i could help happy learning

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .