Код: Выделить всё
int main(int argc, char *argv[]) {
//for getopt
int option;
char *filename;
int fflag = 0;
//checks if no args is given and prints out the help page
if(argc == 1){
help();
return 0;
}
//need to use optget and redo all of the flag logic manually
while((option = getopt(argc, argv, ":hf:")) != -1){
switch(option){
case 'h':
help();
return 0;
case 'f':
//read file name from -f flag
filename = optarg;
fflag = 1;
case '?':
fprintf(stderr, "Unknown option -%c\n",optopt);
return 1;
}
}
//check if -f flag is used
if(fflag == 1){
int errorcode = file(filename,password);
if(errorcode == 1){
fprintf(stderr,"Filename must be of .txt extension\n");
} else if ( errorcode == 2){
fprintf(stderr,"File not found or not able to open\n");
} else if (errorcode == 3){
fprintf(stderr,"Password not found in wordlist\n");
} else if (errorcode == 0){
printf("Password found in word list");
}
return 0;
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... ving-value
Мобильная версия