c - How to print values from an input data file from an array? -



c - How to print values from an input data file from an array? -

i'm finish beginner programmer bear me.

so have input text file utilize input programme in command window using program.exe < data.txt. text file has 5 lines, each line has 3 double values, 30.0 70.0 0.05 etc.

i want utilize array of structures print these input values, printf("the first value %f", array[i][0]).

here wrong code far:

#include <stdio.h> #include <stdlib.h> #define maxsources 100 typedef struct { double x; double y; } coordinates_t; typedef struct { coordinates_t point; double w; } soundsource_t; coordinates_t a; soundsource_t b; int main(int argc, char *argv[]) { int i; while(scanf("%lf %lf %lf", &a.x, &a.y, &b.w) == 3) { soundsource_t soundsource[maxsources][2]; (i = 0; <= maxsources; i++) { printf("%d", soundsource[i][0]); printf("%d", soundsource[i][1]); printf("%d", soundsource[i][2]); printf("\n"); } } homecoming 0; }

can help me prepare code? thanks

sample fix

int main(int argc, char *argv[]) { soundsource_t soundsource[maxsources]; int i, n = 0; while(scanf("%lf %lf %lf", &a.x, &a.y, &b.w) == 3) { soundsource[n].point = a; soundsource[n].w = b.w; n += 1; } (i = 0; < n; i++) { printf("%f,", soundsource[i].point.x); printf("%f ", soundsource[i].point.y); printf("%f\n",soundsource[i].w); } homecoming 0; }

c arrays

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -