如果argv以char结尾,我该如何搜索

时间:2016-09-30 05:20:26

标签: c

我如何检查argv是否以字符结尾?例如,如果我想看看agv [1]是否以字符z结尾,我将如何编写程序。

if(argv[1] == ? )
    printf("The input entered ends with the character z");

1 个答案:

答案 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");
    }
}