c - How to print 2d-array with comma and new line -



c - How to print 2d-array with comma and new line -

int **arr; //for example: 4 3 array

how can print 2d-array comma , new line below?

01, 02, 03, 04 // @ last, new line without comma 05, 06, 07, 08 09, 10, 11, 12

i need fastest method print it.

a simple solution m x n matrix defined double pointer type is:

/* print (m x n) matrix */ void mtrx_prn (size_t m, size_t n, float **matrix) { register size_t i, j; (i = 0; < m; i++) { char *pad = "[ "; (j = 0; j < n; j++) { printf ("%s%6.3f", pad, matrix [i][j]); pad = ", "; } printf ("%s", " ]\n"); } }

output

$ ./bin/mtrx_dyn_example [ 1.900, 2.800, 3.700, 4.600 ] [ 2.800, 3.700, 4.600, 5.500 ] [ 3.700, 4.600, 5.500, 6.400 ]

just adjust info type (e.g. int, double, etc...) needed.

c

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -