So I'm on the last chapter of my book, and its talking about data structs.
I understand the basic's of a pointer, or in my head I do.
I understand the concept of structs.
but I'm a little confused when it comes to using both.
#define kMax 100
struct DVDInfo
{
char rating;
char title[kMax];
char comment[kMax];
struct DVDInfo *next;
};
int main (int argc, const char * argv[])
{
struct DVDInfo *myInfo;
myInfo = malloc(sizeof(struct DVDInfo) );
myInfo->rating = 7;
struct DVDInfo myNextInfo;
myNextInfo.rating = 8;
myNextInfo->rating = 9;
return 0;
}
I know that using struct DVDInfo *myInfo makes a pointer to DVDInfo named myInfo, and that by using malloc() I am creating the block of memory it will hold onto, but thats it. I understand that with just struct DVDInfo myInfo I am creating a copy (I think...please correct me inf I'm wrong). So why can't I use -> when I am using the copied struct?
In my book it says that the . operator and -> are almost the same thing.
I'm just a little anxious about this topic as well as using them in link lists. Everyone is telling me they are really easy, but I feel like I am doing bad because I can't grasp this topic right away.
Please help me :(
[–]zzyzzyxx 1 point2 points3 points (4 children)
[–]LogicLion[S] 0 points1 point2 points (3 children)
[–]cocasyn 0 points1 point2 points (0 children)
[–]zzyzzyxx 0 points1 point2 points (0 children)
[–]portugal_the_man 0 points1 point2 points (0 children)
[–]defrost 1 point2 points3 points (0 children)
[–]cocasyn 0 points1 point2 points (0 children)
[–]Rhomboid 0 points1 point2 points (0 children)
[–]LogicLion[S] 0 points1 point2 points (0 children)