Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- int main(int argc, char** argv) {
- int opt;
- while((opt = getopt(argc, argv, ":h:m:s:")) != -1)
- {
- int num;
- switch(opt)
- {
- case 'h':
- if (sscanf(optarg, "%2d", &num) != 1 || (num < 0 || num > 23)) {
- printf("rip hora\n");
- break;
- }
- printf("hour: %d\n", num);
- break;
- case 'm':
- printf("minute: %s\n", optarg);
- break;
- case 's':
- printf("second: %s\n", optarg);
- break;
- case ':':
- printf("option needs a value\n");
- break;
- case '?':
- printf("unknown option: %c\n", optopt);
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement