C program with Scratchpad and input

Re: C program with Scratchpad and input

by Richard Lobb -
Number of replies: 0

Belatedly ... I attach the prototype for a C write-a-program question that has as custom scanf function that echoes stdin to stdout as it is consumed. This is to simulate KB input. It also has a scratchpad that supports input using the trick described in questions 4 and 5 from the quiz  The Scratchpad UI. I also attach a simple demo (see below).

Was that what you wanted? Let me know if not.

Caveats:

  • It hasn't been tested in a production environment. Let me know of any problems.
  • It handles only scanf for reading input. If you want your students to use getc, fgetc, gets (aargh no), fgets, fscanf, etc you're out of luck. Or will have to implement your own customised versions.
  • The scratchpad area itself isn't much use as you can't usefully add to the end of a C program. But clicking Run does run the main program, prompting for input as it's needed. And you could uncheck the "Prefix with answer" checkbox and then use the scratchpad as a general C programming workspace.
  • As with the Python implementation the trick to simulate interactive input works only if the program behaves deterministically. If, say, it uses random numbers or the real-time clock to control its output, the trick fails.
  • If you want something that works with C write-a-function questions, with the scratchpad containing just the call to the function(s) as a test, you'll need to change the wrapper to wrap the function call in a main function.

`Screenshot of demo question