CPlay/getopt/getopt.c
2025-11-14 20:59:40 +01:00

15 lines
445 B
C

#include <stdio.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
int opt;
while ((opt = getopt(argc, argv, "hf:o:")) != -1) {
switch (opt) {
case 'h': puts("Help"); break;
case 'f': printf("File: %s\n", optarg); break;
case 'o': printf("Output: %s\n", optarg); break;
default: fprintf(stderr, "Usage: %s [-h] [-f file] [-o output]\n", argv[0]); return 1;
}
}
return 0;
}