cannot convert 'record*' to 'record**'

I dont understand why i get this error when i compile my code. I believe that i am doing everything the same as i did previously but it is not working this time.

stack.cpp:30: error: cannot convert 'record*' to 'record**' for argument '2' to 'void filename(char*, record**)'


there are more errors when it is compiled but i will figure them out.
(also i had to (add the 4 spaces per line that signify "code" by hand so if any one else could tell me to how to do that automatically! that would be great!
thansk

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
78
79
80
81
82
83
84
#include <iostream>
     #include <cstdlib>
     #include <fstream>
     #include <stdio.h>
     #include <cstring>
     #include <strings.h>

     using namespace std;

     struct record
     {
     char first [20];
     char mid   [1];
     char last  [20];
     int  ssn;
     };

     void filename (char ifname [], struct record* student[]);
     void structfill (fstream & infile, struct  record*  student []);

     int main ()
     {

     system ("clear");

     fstream infile;
     char ifname [256];
     struct record * student;
     filename (ifname, student);

     return 0;
     }
     /*******************************************************************/
     void filename (char ifname [],record* student [])
     {
     fstream infile;
     cout << "Enter name of file to read from: ";
     cin.getline (ifname, 256);
     cout << endl;
     infile.open (ifname);
        if (!infile.is_open ())
        {
        cerr << "FILELOOP!: Unable to open input file " << ifname
             << endl;
        exit (1);
        }
     structfill (infile, student);
     }
     /*******************************************************************/
     void structfill (fstream & infile, record* student [])
     {

     char buffer [81];
     char buffername [81];
     char bufferfirst [81];
     int n=0;
     int x=0;
     int f=0;

     infile.getline (buffer,81);
     while (!infile.eof ())
     {
      x++;
     cout << "-----------------------" << x;
     if (strncasecmp (buffer, "<student>",9)==0)
     {
     n++;
     cout << "jess sucks" << n;
     student = new *record;
        infile.getline (buffername, 81);
        if (strncasecmp (buffername, "<first>",7)==0)
        {
        f++;
        infile.getline (bufferfirst, 81);
        strcpy (student->first, bufferfirst);
        cout << endl << "######  " << f;
        }
     }
     infile.getline (buffer, 81);
     cout << *student[n]->first;
     cout << "endendendend" << endl;
     }
     }
   
At the main function, you're declaring a pointer and, then, passing it as argument to a function that requires an array of pointers.
Could you be more specific with line numbers? I am still learning.
Thank you very much!
Last edited on
Line 28. After fixing this, remember to allocate memory for it. Because right after it, your code will cause undefined behavior.


Here is an example of what will look like after you fix your code and do not allocate memory for it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

void handle(int *b)
{
    *b = 10000;
}

int main()
{

    int a = 1;
    int *p = &a;

    *p = 2; // this is cool. Because our pointer is pointing to a real object. In this case, "a".

    int *b; // this is garbage. Our pointer is uninitialized and it is pointing to nothing.(invalid memory)
    handle(b);// Here we pass our pointer which is pointing to an invalid memory and do some shit with it. We say that this is undefined behavior.


    return 0;
}
Last edited on
thank you!
Topic archived. No new replies allowed.