3

私の最初の質問に答えてくれてありがとう、でも別の質問があります。ここに strtol() 関数を使用するこのコードがあります。それは機能しますが、問題は、3 つのオプションのいずれかを入力すると、(d 2) 文字列と見なされ、入力 (2d) が文字列であり、(d2) が文字列である場合です。配列内の数値を検出する方法はありますか?

  char userInput[256];
    char *end;
    printf("Please enter your name: ");
    scanf("%s", userInput);
    int userName = strtol(userInput, &end, 10);
    if (!*end)
    {
        printf("You have enter an int");
    }
    else
    {
        printf("You have entered a string");
    }
4

2 に答える 2