Moved to using optind

This commit is contained in:
Gitea 2020-12-13 14:17:23 -06:00
parent ae31e82b64
commit c21c4b2739

9
tee.c
View file

@ -18,19 +18,12 @@ int main(int argc, char * argv[]) {
} }
} }
while(strcmp("-a", argv[start_arg]) == 0 ||
strcmp("-i", argv[start_arg]) == 0 ||
strcmp("-ai", argv[start_arg]) == 0 ||
strcmp("-ia", argv[start_arg]) == 0) {
start_arg++;
}
FILE * files[27] = { 0 }; FILE * files[27] = { 0 };
char * mode = append_mode == 1 ? "a+" : "w+"; char * mode = append_mode == 1 ? "a+" : "w+";
int j = 0; int j = 0;
for(int i = start_arg; i < argc && j < 27; i++) { for(int i = optind; i < argc && j < 27; i++) {
files[j++] = fopen(argv[i], mode); files[j++] = fopen(argv[i], mode);
if(files == NULL) { if(files == NULL) {
fprintf(stderr, "%s: could not open/create file %s\n", argv[0], argv[i]); fprintf(stderr, "%s: could not open/create file %s\n", argv[0], argv[i]);