What my main is supposed to do is either read from stdin using system calls. Or if file arguments are given open the file arguments. I had already coded this to read from one file argument. But now I need it to open from multiple file arguments and I am short on the logic as to how to do this. How would I get my code to be able to open multiple file arguments?
int main(int argc, char *argv[]) { char *file_pathname = NULL; int fd; char file_buffer[540]; //Check for proper number of arguments: if(argc < 2) { exit(2); } if(argc < 3) { file_pathname = "stdin"; } file_pathname = argv[2]; if(argc < 3) { ((fd = read(STDIN_FILENO,file_buffer, FILE_BUFFER_SIZE))); } // FILE argument given, so try to open it: if (argc == 3) { if ((fd = open(file_pathname,O_RDONLY)) == -1) { perror("ERROR OPENING FILE"); return 2; }
for(int i=2; i<argc; i++) { fname = argv[i]; ... }