LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Local <struct pointer> was referenced before being initialized

I've a struct declared...one of its members is "grpName"

in my code:
struct student *thePtr
...

n = Scan (s, "%s[i*]>%s", index, &thePtr->grpName);

Compiling the program generates no error. When the *.exe is run, the error comes from the above line, specifically:

Non-fatal-Run-Time Error
"Local 'thePtr' was refenerced before being initialized."
0 Kudos
Message 1 of 2
(3,235 Views)
Do you initialize the pointer? Declaring it as a pointer reserves space in memory for the pointer, but doesn't assign a value (address of data it's pointing to) to it.
For example:

// pInt is a pointer to an int
int *pInt;
// the next line will fail at run-time
// because pInt hasn't been initialized:
// it doesn't hold a valid address.
*pInt = 5;

To correct that problem,
int *pInt, i;
// save the address of i in pInt
pInt = &i;
// the next line will not fail at run-time
// the pointer pInt is now initialized
// with the address of i
*pInt = 5;
0 Kudos
Message 2 of 2
(3,235 Views)