From 07744bc404fe0be15f6a50ab42d298df77464b81 Mon Sep 17 00:00:00 2001 From: dcw Date: Mon, 27 Mar 2023 00:27:39 +0100 Subject: imported my solutions to this week's tasks, task 1+2 in Perl, task 1 in C also, will do task 2 in C tomorrow when I have time --- challenge-209/duncan-c-white/C/printarray.c | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 challenge-209/duncan-c-white/C/printarray.c (limited to 'challenge-209/duncan-c-white/C/printarray.c') diff --git a/challenge-209/duncan-c-white/C/printarray.c b/challenge-209/duncan-c-white/C/printarray.c new file mode 100644 index 0000000000..ddee597df3 --- /dev/null +++ b/challenge-209/duncan-c-white/C/printarray.c @@ -0,0 +1,39 @@ +#include +#include + + +// print_int_array( maxw, nelements, results[], sep, outfile ); +// format results[0..nelements-1] as a separated +// list onto outfile with lines <= maxw chars long. +// produces a whole number of lines of output - without the trailing '\n' +void print_int_array( int maxw, int nel, int *results, char sep, FILE *out ) +{ + int linelen = 0; + for( int i=0; i maxw ) + { + fputc( '\n', out ); + linelen = 0; + } else if( i>0 ) + { + fputc( ' ', out ); + linelen++; + } + + linelen += len; + fprintf( out, "%s", buf ); + if( i0 ) + //{ + // fputc( '\n', out ); + //} +} -- cgit