gpt4 book ai didi

c - 我如何搜索 argv 是否以 char 结尾

转载 作者:行者123 更新时间:2023-11-30 19:37:30 25 4
gpt4 key购买 nike

我如何检查 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com