Differences between version 6 and revision by previous author of getopt(3).
Other diffs: Previous Major Revision, Previous Revision, or view the Annotated Edit History
Newer page: | version 6 | Last edited on Thursday, October 7, 2004 11:00:26 am | by SamJansen | Revert |
Older page: | version 5 | Last edited on Saturday, September 6, 2003 4:20:13 pm | by JohnMcPherson | Revert |
@@ -274,8 +274,31 @@
}
exit (0);
}
+
+An short and sweet example of getopt usage:
+ int ch; /* Butchered out of [tcpperf|http://www.wand.net.nz/~stj2/nsc/software.html] by SamJansen */
+ while ((ch = getopt(argc, argv, "c:p:s:")) != -1)
+ switch (ch) {
+ case 'c':
+ /* Client machine to connect to */
+ client = optarg;
+ break;
+ case 'p':
+ /* port */
+ port = atoi(optarg);
+ break;
+ case 's':
+ write_size = atoi(optarg);
+ break;
+ case '?':
+ default:
+ usage(argv[[0]);
+ }
+ argc -= optind;
+ argv += optind;
+
!!BUGS