can u see the prob

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
69
70
71
72
73
74
75
76
77
#define STUDENTS_NUM 80
#define MAX_IN_LEC 20
#define LECTURES_NUM 4
#include <stdio.h>
int convert_grades(float a[0][0],char b[],float over)
    {  int c=-1,l=0,i=0, j=0;
        for (i=0; i < LECTURES_NUM; i++)
        {
                for (j=0; (a[i][j] !=(-1)&&(j<MAX_IN_LEC)); j++)
            {
                if ((0<=a[i][j])&&(a[i][j]<=100))
                {
                    c++;
                    if (a[i][j]>=over)
                        {
                         b[c]='p';
                        }
                        else
                        b[c]='f';
                }
                else
                return 1;
            c++;
            b[c]='\0';
            }
        }
        for (i=0;i<LECTURES_NUM;i++)
            {

                if (i>0)
                    {
                        printf ("\n");
                        l++;
                    }
                while (b[l]!='\0')
                        {
                            printf("%c",&b[l]);
                            l++;
                        }
            }
        return 0;
    }


int main()
{
/*init variables*/
int i, j, retval;
float grades[LECTURES_NUM][MAX_IN_LEC];
char grades_as_strings[STUDENTS_NUM + LECTURES_NUM];
float pass_grade;
for (i=0; i < LECTURES_NUM; i++)
for (j=0; j < MAX_IN_LEC; j++)
grades[i][j] = -1;
/*enter the grade matrix*/
for (i=0; i < LECTURES_NUM; i++){
printf("Please enter the grades for lecture number %d: \n", i);
scanf("%f", &grades[i][0]);
if (grades[i][0] == -1)
return 1;
for (j=1; j < MAX_IN_LEC; j++)
if (getchar() == '\n')
break;
else
scanf("%f", &grades[i][j]);
}
/*enter the passing grade*/
printf("Please enter the passing grade: ");
scanf("%f", &pass_grade);
/*call the averaging function*/
retval = convert_grades(grades, grades_as_strings, pass_grade);
if (retval){
printf("Invalid input!");
return retval;
}
return 0;
}

i get this eror
cannot convert float (*)[20] to float (*) [ou]for argument 1 to cahr con...
tnx
badCode.cpp: In function ‘int convert_grades(float (*)[0], char*, float)’:
badCode.cpp:37: warning: format ‘%c’ expects type ‘int’, but argument 2 has type ‘char*’
badCode.cpp: In function ‘int main()’:
badCode.cpp:71: error: cannot convert ‘float (*)[20]’ to ‘float (*)[0]’ for argument ‘1’ to ‘int convert_grades(float (*)[0], char*, float)’

So, the warning at line 37; %c indicates an integer type. You probably mean %s, which indicates a char*.

line 71; the function grades accepts something of type ‘float (*)[0]’. You are trying to pass it something of type ‘float (*)[20]’. You can make this much easier on yourself by switching to C++ and using a container class such as std::vector. That's not a great answer, I know, but when I start seeing things like float(*)[20] hanging around, I simplify it all before I shoot myself in the foot.
Last edited on
Topic archived. No new replies allowed.