Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

I'm new to programming in C.


ghost's Avatar
0 0

I took most of this from a book and tryed to add my own code to see if I could get it to work. int y doesn't print 120 and I'm not too sure why. I don't want the answer I would like hits on what I did wrong.

#include <stdio.h> /* standard i/o include file*/

struct xampl {       
  int x;
  int y;
};

int main()
{  
    struct xampl structure;
    struct xampl *ptr;
    struct xampl y;

    structure.x = 12;
    structure.y = 120;
    
    ptr = &structure;  
    
    printf( "%d\n", ptr->x );  /* The -> acts somewhat like the * But it gets what is at that memory address*/
    printf("%d\n", y);  
    
    
    getchar();
    return 0;
}

ghost's Avatar
0 0

// printf("%d\n", y); this is wrong ! it should be printf("%d\n",structure.y); use the structure variable


ghost's Avatar
0 0

TweakedEh wrote: I don't want the answer I would like hits on what I did wrong.

Thanks for the help but I wouldn't mind a hint next time ;)


Uber0n's Avatar
Member
0 0

So you can't code in C but you don't want people to tell you exactly what's wrong with your code…? :right:


ghost's Avatar
0 0

…dude…. Thats fucking annoying, your being ignorant and unclear. Why dont you bury your computer in Egypt and try to shove a pyramid up your ass cuz thats about all your 'intellectual' mind will be able to comprehend. Nah jk haha. Just don't be so annoying, consider yourself mildly chastised/flamed.


ghost's Avatar
0 0

Uber0n wrote: So you can't code in C but you don't want people to tell you exactly what's wrong with your code…? :right:

No, I can code in C but not a lot. I'm still learning and couldn't find my mistake. I have a book here that I am reading, I added some of my own code to that to have a better understaning of what it does and how it works. I asked for a hint because I don't like being spoon fed.