Question

How is the Custom Run sheet Program Input field used in CodeRunner say for a C or Objective-C program?

Was it helpful?

Solution

The text entered in the Program Input text box will be sent to your program/script through the standard input. You can access the input in the same way that you would access the standard input using your language of choice.

In C, you'd use the standard fread, fgets, fgetc etc functions. The following example will echo the supplied text in the Program Input to the console:

#include <stdio.h>

int main(int argc, char *argv[]) {
    char str[80];

    while(fgets(str, sizeof(str), stdin)) {
        printf("%s", str);
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top