我如何检查 argv 是否以字符结尾?例如,如果我想查看 agv[1] 是否以字符 z 结尾,我该如何编写程序。
if(argv[1] == ? )
printf("The input entered ends with the character z");
最佳答案
#include <stdio.h>
#include <string.h>
int main(int argc, char** argv)
{
int string_length;
if(argc < 2)
printf("\n no arguments \n");
else if(argc > 1)
{
string_length = strlen(argv[1]);
if(argv[1][string_length - 1] == 'z')
printf("\n The input entered ends with the character z \n");
else
printf("\n The input entered ends without the character z \n");
}
}
关于c - 我如何搜索 argv 是否以 char 结尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39784190/