C++ 错误代码 Format '%c' expects argument of type 'int'

c++ error code Format '%c' expects argument of type 'int'

我是 C++ 的新手,我制作了一个程序,它接受一个命令行参数并计算有多少个参数,然后打印出字符的数量以及其中有多少是按字母顺序排列的。我收到此错误代码 格式“%c”需要类型为 'int' 的参数,但参数 2 的类型为 'char*'

(我的代码)

#include<cstdio>
#include<cctype>
#include<cstdlib>
#include<cstring>
int main(int argc, char *argv[])
{
    /*
    irrelevant 
    printf 
    statements
    */

    for(pos=0; pos < maxCharLen; pos++){
        int count;

        char totalLen = strlen(argv[pos]);
        char totalAlpha (isalpha(argv[pos][pos]);

        printf("Argument %d is", count);
        printf("%c and %c is it's length.\n", argv[pos], totalLen);
        printf("%c are alphabetic characters\n", totalAlpha);
        count ++
    count++;
    }
    return 0;
}

argvchar* 的数组,所以 argv[pos] returns char* 所以你应该使用 %s。毕竟正确的格式是:

printf("%s and %c is it's length.\n", argv[pos], totalLen);