This is starting to piss me off :-(

What is wrong with this code?
Compiling error:
`fullname' has not been declared


1
2
3
4
5
6
7
8
9
10
11
12
struct student{
char fullname[30];
char hobby[30];
int ooplevel;
};
int getinfo(student* students[], int size){
    for(int i=0; i<size; i++){
        cout << "Student (" << (i+1) << ")\n";
        cout << "Enter name: ";
        cin.get((students+i)->fullname,30);    <--  [COMPILE ERROR OCCURENCE]
    }
}
Last edited on
Do you know what student* students[] means? Array of student pointers. Is this what you want?
Yeah, I want an array of student strucs than can be accesed through the -> (assignment operator) AKA pointers.

The problem for me right now is, that I have problems with accessing the char variables for some reason?!
Oh wait, seems I fixed it with:
cin.get((*students+i)->fullname,30);

Have no idea why this works tho.
Just do this: int getinfo(student* students, int size){.


I made a mistake maybe... I need to see more of the code to tell for sure.
Last edited on
Mehh. My program became I giant clusterfuck.

Tho I found the real reason for the problem.

It's not:
int getinfo(student* students[], int size)

But instead:
int getinfo(student students[], int size)
or:
int getinfo(student* students,int size)

They're both the same cause an array is the same as a pointer and the other way around.

Anyways, atleast I learned something today ;)
Last edited on
Minimacfox wrote:
They're both the same cause an array is the same as a pointer and the other way around.

An array is not the same as a pointer. It's just that both syntaxes, when used in the function parameter list, declares a pointer.
Last edited on
closed account (zb0S216C)
1
2
3
4
5
6
7
8
int getinfo(student students[], int size){ // "students" parameter changed
    for(int i=0; i<size; i++){
        cout << "Student (" << (i+1) << ")\n";
        cout << "Enter name: ";
        cin.get((students+i)->fullname,29); // Reduced 2nd parameter to 29 
                                            // to save space for a null-character
    }
}


Minimacfox wrote:
"They're both the same cause an array is the same as a pointer and the other way around."


1
2
3
void Function int Array[] );   // IS: int Array*
void Function int *Array[] );  // IS: int Array**
void Function int Array[][] ); // IS: int Array**  

Wazzak
Last edited on
Framework wrote:
1
2
cin.get((students+i)->fullname,29); // Reduced 2nd parameter to 29 
                                    // to save space for a null-character 
This is unecessary because get already takes the null-character in to account.

Framework wrote:
void Function int Array[][] ); // IS: int Array**
Even if you add the missing parenthesis this is not valid.
Last edited on
Even if you add the missing parenthesis this is not valid.

Indeed. There's a technical reason why you always need to specify all but one of a multidimensional array's dimensions... the computer needs that information to correctly determine the offset... I think.
Topic archived. No new replies allowed.