我正在编写一个C程序,它可以接受来自命令行的字符输入。如果用户在命令行输入字符,程序应该打印这些字符的ascii值。我遇到了以下问题:1)编写printf语句; 2)如果用户没有从命令行发送任何内容,则跳过打印输入。以下是我已经写了:C:打印元素* argv
int main(int argc, char *argv){
char thisChar; //Holds the character value of the current character.
int ascii; //Holds the ascii value of the current character.
int x = 1; //Boolean value to test if user input 0, our while loop break condition.
int i = 0; //Counter for the following for loop
if(argc > 0){
for(i; i<argc; i++){
thisChar = argv[i];
printf("%c\nAscii: %d\n", thisChar, thisChar);//prints the character value of thisChar followed by its ascii value.
}
printf("Done.");
}
}
当我把它从这样的命令行:
./ascii F G h
输出是:
�
k
�
�
Done.
是我printf的问题声明?为什么if条件评估为真,即使我没有输入?
咦? 'int main(int argc,char * argv)' – this