Skip to content

Instantly share code, notes, and snippets.

// gcc -o run_inferior run_inferior.c -W -Wall
/* A function to execute a child program and feed the input line-by-line back
* to the calling program. The function mst be called with a callback function
* that will receive each line as it is read in, a program to execute and the
* command line arguments for that program.
*
* There are two versions of this function: one that takes the command line
* arguments as variadic parameters delimited with a NULL pointer and one that
* takes an array of parameters with a length specified for the array.
@lelanthran
lelanthran / process_args_test.c
Last active August 31, 2019 22:30
More comprehensive c/line arguments processing
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
/* ********************************************************************
* An even more comprehensive command-line parsing mechanism. This method
* allows the program to have long options (--name=value) short options
* (-n value or -nvalue or -abcnvalue) mixed with non-options (arguments
* without a '-' or '--'.
@lelanthran
lelanthran / cline_test.c
Last active May 27, 2019 21:15
Single function to get command-line options in both long and short form.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
/* *****************************************************************
* A more robust command-line handling function than I normally use.
* There are only two functions, so this is suitable for copying and
* pasting into the file containing main().