Array as struct database?

Posted by user2985179 on Stack Overflow See other posts from Stack Overflow or by user2985179
Published on 2013-11-12T21:51:00Z Indexed on 2013/11/12 21:53 UTC
Read the original article Hit count: 107

Filed under:

I have a struct that reads data from the user:

typedef struct
{
    int seconds;
} Time;

typedef struct
{
    Time time;
    double distance;
 } Training;


 Training input;

 scanf("%d %lf", input.time.seconds, input.distance);

This scanf will be looped and the user can input different data every time, I want to store this data in an array for later use. I THINK I want something like arr[0].seconds and arr[0].distance.

I tried to store the entered data in an array but it didn't really work at all...

Training data[10];

data[10].seconds = input.time.seconds;
data[10].distance = input.distance;

The data will wipe when the program closes and that's how I like it to be. So I want it to be stored in an array, no files or databases!

© Stack Overflow or respective owner

Related posts about c