Problem with file types

So basically I found a program in some forums but it had static string while my program had dynamic string. I tried to change the program I found but I have run into a problem

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
bool valid (bool condition, const char* message)
{
    if (!condition)
        printf ("### %s!\n", message);
    return condition;
}
 float det(int x, float** f)
{
  int d=0, j, p, q, t;
  float pr;
  float** b;
  float** c;
  b=new float*[20];
        if (!valid(b, "unable to allocate memory"))
            return NULL;
        for (int i=0; i<20; i++)
        {
            b[i]=new float[20];
            if (!valid(b[i], "unable to allocate memory"))
                return NULL;
        }
        c=new float*[20];
        if (!valid(c, "unable to allocate memory"))
            return NULL;
  if(x==2)
  {
    d=(f[1][1]*f[2][2])-(f[1][2]*f[2][1]);
    return d;
   }
  else
  {
    for(j=1;j<=x;j++)
    {
      int r=1,s=1;
      for(p=1;p<=x;p++)
        {
          for(q=1;q<=x;q++)
            {
              if((p!=1) && (q!=j))
              {
                b[r][s]=f[p][q];
                s++;
                if(s>x-1)
                 {
                   r++;
                   s=1;
                  }
               }
             }
         }
     for(t=1,pr=1;t<=(1+j);t++)
     pr=(-1)*pr;
*     c[j]=pr*det(x-1,b);
    }
     for(j=1,d=0;j<=x;j++)
     {
       d=d+(f[1][j]*c[j]);
      }
     return(d);
   }
}


In the line that I marked with a * an error occurs |error: cannot convert 'float' to 'float*' in assignment|
I want to ask if there is any way to fix it or should I start over?
c points to a pointer (**). And when you subscript c, it returns a reference to that element. When you subscript c you get a pointer. You can only assign pointers to pointers or addresses (address-of operator). And you are trying to assign float to a pointer to float.
Last edited on
So can I actually fix it and how?
Either declare c as type float or make sure the expression on line 53 returns type float*.
Last edited on
But if I change c type to float then lines 53 and 57 don't make sense. And also I don't know how to change line 53 to return float*. Sorry, I'm just green in programming and don't know a lot
Last edited on
Topic archived. No new replies allowed.