我如何检查argv是否以字符结尾?例如,如果我想看看agv [1]是否以字符z结尾,我将如何编写程序。
if(argv[1] == ? )
printf("The input entered ends with the character z");
答案 0 :(得分:0)
#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");
}
}