Anthony Bahlman Anthony Bahlman - 1 month ago 6
C Question

Error message in c invalid binary

I'm getting an error:

Type invalid operands to binary & (have 'int *' and 'int')

here is my program. The problem occurs at line 34 or the

#include <stdio.h>
#include <stdlib.h>

FILE *infile;
FILE *prnt;
int num1, num2, nums;
char complex;
float fcost;
char name [11];
infile = fopen ("F:/DATA.txt", "r");
prnt = fopen ("F:/income.txt", "w");
if (infile == 0)
printf ("FILE NOT ON DISK\n");
return 0;
fprintf (prnt, "%-15s %-23s %6s\n\n", "ABAHLMAN", "Program 1", "PAGE 1");
fprintf (prnt, "\n");

fscanf (infile, " %i %i %i %f %c", &nums &num1 &num2 &fcost &name);

while (!feof (infile))
int area = (nums * 200) + (num1 * 300) + (num2 * 450);
float cost = fcost + (area * 75.00);
double income = 12 * ((nums *450) + (num1 * 550) + (num2 *700));
float payback = cost/ income;

fprintf (prnt, "%-10s %5f %7c %9.2f\n", name, payback, area, cost);
fscanf (infile, " %d %d %d %f %c", &nums &num1 &num2 &fcost &name);

fclose (infile);
fclose (prnt);
return 0;


usr usr

You are not separating the arguments with comma in fscanf() statements. They should be:

fscanf (infile, " %i %i %i %f %s", &nums, &num1, &num2, &fcost, name);


fscanf (infile, " %d %d %d %f %s", &nums, &num1, &num2, &fcost, name);

Note that name is an array and it gets converted into a pointer when you pass it to fscanf(). So, the & operator needs to be dropped. As noted in the comments, the format should be %c for name.

Also, see: What is array decaying?

I'd also suggest to use a standard definition for main() function. main() {..} is outdated and should be avoided. Instead, you can write it as int main(int).