> It comes on the 2nd char buff[BUFSIZ] line.
Because now you're writing C++
In C, all variables must be declared at the start of the block.
In this case, the 2nd declaration of buff is unnecessary - just delete it.
The code should be
Code:
while (fgets(buff, BUFSIZ, inventry_fp) != NULL)
{
int res = sscanf(buff, "%[^0-9] %d %s %f", str_1,
&inventry_code, str_2, &price_per_item);
if(res != 4)
{
printf("Error - did not convert all the expected values!");
}
// you only want to read one line from this file
// to match the single line from the other file
if (fgets(buff, BUFSIZ, instock_fp) != NULL)
{
int res = sscanf(buff, "%d %d", &number_in_stock, &instock_code);
if(res != 2)
{
printf("Error - did not convert all the expected values!");
}
}
if (inventry_code == instock_code)
{
total_price_in_stock = number_in_stock * price_per_item;
report_code = instock_code;
fprintf(report_fp, "%d %s %d %f", report_code, str_1,
number_in_stock, total_price_in_stock);
}
else
fprintf(stderr, "Inventry Code of: %d does not match instock_code of: %d\n",
inventry_code, instock_code);
}