I am writing a program that is a custom version of ls with some options. The options can be inputted as "-i" or as something like "-ilR". This portion of my code iterates through the command line arguments and sets a struct accordingly. Except if I run the program with "./myProgram -i Directory" it doesn't go into the test print I have set up.
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <sys/fcntl.h>
#include <stdbool.h>
#include <string.h>
struct optionArguments{
bool argumenti;
bool argumentl;
bool argumentR;
};
int main(int argc, char* argv[]){
struct optionArguments options;
options.argumenti = false;
options.argumentl = false;
options.argumentR = false;
for(int i = 1; i<argc-2; i++){
for(int j = 0; j<strlen(argv[i]); j++){
char chr = argv[i][j];
if(chr == 'i'){
options.argumenti = true;
}
if(chr == "l"){
options.argumentl = true;
}
if(chr == "R"){
options.argumentR = true;
}
}
}
if(options.argumenti){
printf("OPTION I\n");
}
}
any help/advice is greatly appreciated
edit: I just put a test print inside of the second loop and it doesn't print anything at all so the second loop isn't even running.