This avoids the warning about it being unused with -Wunused.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
* #include <ccan/cast/cast.h>
* #include <stdint.h>
* #include <stdio.h>
* #include <ccan/cast/cast.h>
* #include <stdint.h>
* #include <stdio.h>
*
* // Find char @orig in @str, if @repl, replace them. Return number.
* static size_t find_chars(char *str, char orig, char repl)
*
* // Find char @orig in @str, if @repl, replace them. Return number.
* static size_t find_chars(char *str, char orig, char repl)
+ * if (argc != 2) {
+ * fprintf(stderr, "Needs argument\n"); exit(1);
+ * }
* // find_chars wants a non-const string, but doesn't
* // need it if repl == 0.
* printf("%zu %c's in 'test string'\n",
* // find_chars wants a non-const string, but doesn't
* // need it if repl == 0.
* printf("%zu %c's in 'test string'\n",
*
* int main(int argc, char *argv[])
* {
*
* int main(int argc, char *argv[])
* {
- * if (argv[1] && streq(argv[1], "--verbose"))
+ * if (argc > 1 && streq(argv[1], "--verbose"))
* printf("verbose set\n");
* printf("verbose set\n");
- * if (argv[1] && strstarts(argv[1], "--"))
+ * if (argc > 1 && strstarts(argv[1], "--"))
* printf("Some option set\n");
* printf("Some option set\n");
- * if (argv[1] && strends(argv[1], "cow-powers"))
+ * if (argc > 1 && strends(argv[1], "cow-powers"))
* printf("Magic option set\n");
* return 0;
* }
* printf("Magic option set\n");
* return 0;
* }
- * if (argv[1]) // Mangle in place.
+ * if (argc > 1) // Mangle in place.
* b = base(take(argv[1]));
* else
* b = base("test/string");
* b = base(take(argv[1]));
* else
* b = base("test/string");
+ * if (argc > 2)
+ * err(1, "Takes 0 or 1 arguments");
* file = grab_file(NULL, argv[1]);
* if (!file)
* err(1, "Could not read file %s", argv[1]);
* file = grab_file(NULL, argv[1]);
* if (!file)
* err(1, "Could not read file %s", argv[1]);
* char *textfile;
* char **lines;
*
* char *textfile;
* char **lines;
*
+ * if (argc > 2)
+ * errx(1, "Takes 0 or 1 arguments");
* // Grab lines in file.
* textfile = grab_file(NULL, argv[1]);
* if (!textfile)
* // Grab lines in file.
* textfile = grab_file(NULL, argv[1]);
* if (!textfile)
* // Silly game to find the longest chain of values.
* int main(int argc, char *argv[])
* {
* // Silly game to find the longest chain of values.
* int main(int argc, char *argv[])
* {
- * int i, run = 1, num = argv[1] ? atoi(argv[1]) : 0;
+ * int i, run = 1, num = argc > 1 ? atoi(argv[1]) : 0;
*
* for (i = 1; i < 1024;) {
* // Since run is an int, compiler checks "add" does too.
*
* for (i = 1; i < 1024;) {
* // Since run is an int, compiler checks "add" does too.