I need to create an array of structs but I have to read the array size from a file. My problem is that I might be using the pointers all wrong. I can't use global variables. Here's the code I made :
#include <stdio.h>
#include <stdlib.h>
struct driver
{
int *amount;
int ADT1[9];
int ADO1[9];
};
struct driver totaldrivers[*amount];
The errors(2) I get are "amount undeclared here(not in a function)" and "storage size of 'totaldrivers' isn't known". I tried giving the *amount a value directly but no luck and even so the amount must be taken by the file the user has created and the number is the first line. And that's where I have my issue. The (.txt)file format is:
4(amount of entries)
123456789 , 978675645 (ADT1,ADO1)
.
.
.
I am sure I've made rookie mistakes so forgive me if the question is silly.
amountis not a global variable, you need an initializeddriverstructure instance to access it.intper digit. Instead a singleunsigned intwill be enough.