numtools

perform numerical operations on vectors and matrices in unix pipes
git clone git://src.adamsgaard.dk/numtools # fast
git clone https://src.adamsgaard.dk/numtools.git # slow
Log | Files | Refs | README | LICENSE Back to index

transpose.c (473B)


      1 #include <err.h>
      2 #include <stdio.h>
      3 #include <stdlib.h>
      4 #include <unistd.h>
      5 
      6 #include "util.h"
      7 
      8 int
      9 main(void)
     10 {
     11 	size_t i, j, nf, nr;
     12 	double **vals = NULL;
     13 
     14 	if (pledge("stdio", NULL) == -1)
     15 		err(2, "pledge");
     16 
     17 	nr = fscanmatrix(stdin, &vals, &nf);
     18 
     19 	for (i = 0; i < nf; i++) {
     20 		for (j = 0; j < nr; j++) {
     21 			printf("%.17g", vals[j][i]);
     22 			if (j < nr - 1)
     23 				printf(DELIMSTR);
     24 		}
     25 		puts("");
     26 	}
     27 
     28 	for (i = 0; i < nr; i++)
     29 		free(vals[i]);
     30 	free(vals);
     31 
     32 	return 0;
     33 }