字符串比较函数strcmp返回值取值1, 0, -1, 返回值取不同的值对于使用这个返回值很有帮助,增加了它的功能性。
int main(int argc, int *argv[])
其中argc是包含argv[0]的系统路径和命令行参数个数, 注意:argc是命令行总的参数个数,不是在 程序中运行中输入的个数
测试代码:
#include <stdio.h>
#include <string.h>
char pass[] = "abcd";
int validate_user(){
char buff[5];
printf("Enter your password:\n");
gets(buff);
return !strcmp(pass, buff);
}
int main(int argc, char *argv[]){
if(validate_user()){
printf("Your password is correct.\n");
}
else {
printf("your password is not correct.\n");
}
printf("%d\n", argc);
for (int i=0; i<argc; i++){
printf("Argument %d is %s.\n", i, argv[i]);
}
}