Chase Convery Chase Convery - 16 days ago 6
C++ Question

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

I am pretty new to C++ and making a program that takes a command line argument and counts how many arguments there are then prints the amount of characters and how many of them are alphabetical. I am getting this error code
Format '%c' expects argument of type 'int', but argument 2 has type 'char*'

(my code)

#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;
}

Answer

argv is array of char* so argv[pos] returns char* so you should use %s. After all correct format is:

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