So a friend of mine sent me this but unfortunately my C skills are a bit rusty so I might be missing something easy. The problem exists in the second fscanf
command.
The error is [Error] expected primary-expression before '[' token
. It might be something it's easily missed but I tried searching for a bit before posting this. Any help is appreciated!
struct materials
{
char name,product;
int code,code1,number_of_parts,quantity1,number_of_parts1,quantity2;
};
typedef struct materials mater;
int main()
{
int result(int x) ;
int number1,j,i,result1,number2,k,z;
FILE *fp;
materials* listOfMaterials;
fp = fopen("datain.txt", "r");
if (fp!=NULL)
{
fscanf(fp, "%d\n",&number1);
listOfMaterials = (mater*)malloc(number1 * sizeof( mater));
for(j=1; j<number1; j++) {
fscanf (fp, "%d %d %d %s\n", &mater[j].code, &mater[j].quantity1, &mater[j].number_of_parts, mater[j].name);
if (mater[j].quantity1 != 0)
{
mater[j].code1=(int *)malloc(sizeof(int)*mater[j].quantity1);
mater[j].number_of_parts1=(int *)malloc(sizeof(int) * mater[j].quantity1);
fscanf (fp,"%d %d\n",&mater[j].code1,&mater[j].number_of_parts1);
}
}