~brenns10/sc-argparse

5e9941fdfae1d0cdf79a42497e131068101b570c — Stephen Brennan 4 years ago fffc4e4
Fix off-by-one in example.c
1 files changed, 4 insertions(+), 4 deletions(-)

M src/example.c
M src/example.c => src/example.c +4 -4
@@ 21,22 21,22 @@ enum my_args {

int main(int argc, char **argv)
{
	struct sc_arg args[NUM_ARGS];
	struct sc_arg args[NUM_ARGS + 1];
	int rv;
	args[ARG_HOST] = SC_ARG_STRING('H', "--host", "host to connect");
	args[ARG_PORT] = SC_ARG_DEF_INT('p', "--port", 80, "port to connect");
	args[ARG_VERBOSE] = SC_ARG_COUNT('v', "--verbose", "print more");
	args[NUM_ARGS - 1] = SC_ARG_END();
	args[NUM_ARGS] = SC_ARG_END();

	if ((rv = sc_argparse(args, argc - 1, argv + 1)) >= 0) {
		printf("Parsing successful!\n");
		printf("Parsing successful! rv=%d\n", rv);
		printf("Host: %s\n", args[ARG_HOST].val_string);
		printf("Port: %d\n", args[ARG_PORT].val_int);
		printf("Verbose: %d\n", args[ARG_VERBOSE].val_int);
		printf("Posargs (%d):\n", rv);
		printargs(rv, argv + 1, "posargs");
	} else {
		printf("error\n");
		printf("error rv=%d\n", rv);
		return 1;
	}
	return 0;