mercredi 18 novembre 2020

Could someone explain why my last else statement will not run?

Im trying to convert my argv string into an integer. For some I can't get my last else statement to run. Any help would be greatly appreciated. Im just starting with C. Here is my code.

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


int main(int argc, string argv[])
{
    if (argc == 2)
    {
        for(int i = 0, n = strlen(argv[1]); i < n; i++)
        {
            if (!isdigit(argv[1][i])) {
            printf("Usage: ./caesar key\n");
            
            }
            
        }
    }
        else if (argc != 2)
        {
            printf("Usage: ./caesar key\n");
        }
        
        else if (argc == 2)
        {
            int x = atoi(argv[1]);
            printf("%i", x);
            return 0;
        }
}

Aucun commentaire:

Enregistrer un commentaire