|
-
Apr 14th, 2002, 01:37 PM
#1
Thread Starter
Addicted Member
pointer to a struct
i have this struct:
struct temp_rec
{
int iYear;
int iMonth;
int iTemp;
int iLoc;
char* sLoc;
}*trPtr;
and im trying to write values into the pointer and read from the pointer like this:
printf("Please enter the location: ");
scanf(trPtr->sLoc);
its causing a stack dump so i know there is something wrong. There is nothing that goes near the struct anywhere else in the program. what am i doing wrong? I want to use pointers to conserve memory usage. plus i havent really used pointers much, i could do with the practice.
-
Apr 15th, 2002, 08:56 AM
#2
You have to have the pointer aimed at memory where the datatype lives. Here is one way to do that:
Code:
struct temp_rec
{
int iYear;
int iMonth;
int iTemp;
int iLoc;
char* sLoc;
}*trPtr, mystruct;
trPtr = &mystruct;
-
Apr 15th, 2002, 01:44 PM
#3
And you have to allocate memory for the string.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|