我正在使用VS 2015社区。我想调试代码,因此想要传递命令行参数。以下是使用格式和代码片段,用于读取参数。
int main(int argc, char **argv) {
if(argc < 2) { //No file name provided!
print_usage();
return -1;
}
FILE *bin_out=NULL;
int i;
//Scan every option but last one(file name)
for(i=1;i<argc-1;i++) {
if(strcmp(argv[i], "-w") == 0) {
rabin_sliding_window_size=get_uintval_from_arg(argc,i,argv,RAB_POLYNOMIAL_MIN_WIN_SIZE,RAB_POLYNOMIAL_MAX_WIN_SIZE);
if(rabin_sliding_window_size > 0)
i++;
else
return -1; //Illegal value, we are done!
} else if(strcmp(argv[i],"-m") == 0) {
rabin_polynomial_min_block_size=get_uintval_from_arg(argc-1,i,argv,1,UINT_MAX);
//May eventually actually add a limit here someday
if(rabin_polynomial_min_block_size > 0)
i++;
else
return -1;
} else if(strcmp(argv[i],"-x") == 0) {
rabin_polynomial_max_block_size=get_uintval_from_arg(argc-1,i,argv,1,UINT_MAX);
if(rabin_polynomial_max_block_size > 0)
i++;
else
return -1;
} else if(strcmp(argv[i],"-x") == 0) {
rabin_polynomial_max_block_size=get_uintval_from_arg(argc-1,i,argv,1,UINT_MAX);
if(rabin_polynomial_max_block_size > 0)
i++;
else
return -1;
} else if(strcmp(argv[i],"-a") == 0) {
rabin_polynomial_average_block_size=get_uintval_from_arg(argc-1,i,argv,1,UINT_MAX);
if(rabin_polynomial_average_block_size > 0)
i++;
else
return -1;
} else if(strcmp(argv[i], "-o") == 0) {
if(i+1 < argc-1 ) {
i++;
bin_out=fopen(argv[i],"wb+");
if(bin_out == NULL) {
fprintf(stderr,"Could not open file %s for writing, error code is %d!\n",argv[i],errno);
}
} else {
fprintf(stderr,"Must specify file to output to.\n");
print_usage();
return -1;
}
}
我将命令参数(在项目属性页面中)设置为
-o debgtst -w 32 -a 4098 -m 1024 -x 34762 input_file.pdf
但它提供了许多错误
sample.exe已退出,代码为-1(0xffffffff)
如果有帮助: - 我使用以下命令行参数
在Centos 7上运行它sample -o debgtst -w 32 -a 4098 -m 1024 -x 34762 input_file