expression must be a modifiable lvalue

I get something wrong at line 45 with C board when I add two board in "add" function. I had modified "unsigned long" in fron of "fb" and "fc". But it just effect on fb. And else error is '+' cannot add two pointer. I think this is the main error.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
void input(float);
void output(float);
void add(float, float, float);
float max(float);

int in;

float max(float fa[MAX][MAX])
{
float fmax;
fmax = fa[0][0];         
for (int i = 0; i < in; i++)
for (int ij = 0; ij < in; ij++)
if (fmax < fa[i][ij])   
fmax = fa[i][ij];     
return fmax;              
}
//
void input(float fa[][MAX])
{
for (int i = 0; i < in; i++)
for (int ij = 0; ij < in; ij++)
{
printf("Nhap vao ptu[%d][%d]: ", i, ij);
scanf_s("%f", &fa[i, ij]);
}
}


void output(float fa[][MAX])
{
for (int i = 0; i < in; i++)
{
for (int ij = 0; ij <MAX; ij++)
printf("%5.2f", fa[i][ij]);
printf("\n");
}
}


void add(float fa[][MAX], float fb[][MAX], float fc[][MAX])
{
for (int i = 0; i < in; i++)
for (int ij = 0; ij < in; ij++)
	/*(unsigned long)*/ fc[i, ij] = fa[i, ij] + (unsigned long )fb[i, ij];//Error here.
}

void main(void)
{
float fa[MAX][MAX], fb[MAX][MAX], fc[MAX][MAX];
printf("Nhap vao cap ma tran: ");
scanf_s("%d", &in);
printf("Nhap lieu ma tran a: \n");
input(fa);
printf("Nhap lieu ma tran b: \n");
input(fb);
printf("Nhap lieu ma tran c: \n");
input(fc);
add(fa, fb, fc);
printf("Ma tran a: \n");
output(fa);
printf("Ma tran b: \n");
output(fb);
printf("Ma tran c: \n");
output(fc);
printf("So lon nhat cua ma tran c la: %5.2f.\n", max(fc));
_getch();
}
Where is MAX defined? Is this not the whole file? I don't see any includes either.

This:
void main(void)

should be :

void int main(void)

All your functions except max are void, and you haven't used references or pointers, so the original array isn't changed. All the arrays are out of scope of each other.

Why do you want to cast to unsigned long?

The usual convention is to put the definition of functions after main.

Hope all goes well
Last edited on
Thanks! I'll try your way!
Topic archived. No new replies allowed.