c - 如何处理-?在命令行中使用 C?
问题描述
我必须处理命令行输入,如果参数之一等于“-?”,我必须写下我在这里所做的解释是我的代码的样子:
#include <stdio.h>
#include <string.h>
#include "header.h"
#define ul unsigned long
int main(int argc, char *argv[]){
for(int i = 0; i < argc; i++){
printf("%s\n", argv[i]);
}
if(argc > 1){
if(strcmp(argv[1], "-?") == 0){
printf("Here I compare 2 strings using my prototype of strcmp(). You have to pass .\\a.out and 2 strings you want to compare.\nIf you want to see their length, type -v after passing values of strings:)\n");
}
}
if(argc > 3){
if(strcmp(argv[3], "-v") == 0){
printf("The length of the 1st string: %lu\nThe length of the 2nd string: %lu\n", strlen(argv[1]), strlen(argv[2]));
}
}
char *s1 = argv[1];
char *s2 = argv[2];
printf("%i\n", strcmp1(s1, s2));
}
如果我通过了,这就是我得到的./a.out -?
:
zsh: no matches found: -?
所以,我的问题是我如何处理“-?”?
解决方案
推荐阅读
- amazon-cloudwatch - 基于自定义指标的指标名称跨所有维度的 Cloudwatch 警报
- bash - /bin/ls: 参数列表太长
- python - 在 Python 中使用 sortedcontainers 来模拟 BST
- r - ggplot图中的多行x轴
- python - 如何让 input() 考虑将整个字符串插入到列表中?
- node.js - 与 MongoDB Atlas 连接时出现问题
- json - VS Code 内置颜色选择器功能在 JSON 文件中不起作用
- php - 计算PHP中的工作时间时差
- html - 如何使用里面的内容为 div 设置动画?
- c++ - C++ 运行时间正在增加