Looking for C mentor

This is a discussion on Looking for C mentor within the C Programming forums, part of the General Programming Boards category; I've started an online C programming course which is non interactive and the teacher recommends finding someone who knows C ...

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    13

    Looking for C mentor

    I've started an online C programming course which is non interactive and the teacher recommends finding someone who knows C to help me out when I get in trouble or need some help. If anyone is interested in helping me with any questions or problems I may have please let me know by sending me an email to scarr@kua.com or reply back to this post. I will not be able to pay any fee for this help.

    Thanks,
    Shane

  2. #2
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    Unless you are having continous trouble, why not just post on this forum whenever you are having a problem you can't solve?

  3. #3
    Registered User
    Join Date
    Feb 2005
    Posts
    13
    I just thought it would be easier dealing with on person and I also didn't want to post homework question on forum because i know people get mad when users do that. I'm doing the work on my own just want to run it by someone to make sure it's right and if not show me what I'm doing wrong. If the forum is ok with me posting that stuff I'd be glad to.

    Shane

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    Thats what the forum is for, to help you when you have problems getting for example a wrong output or having problems with a function etc provided you have done some work of course.
    When no one helps you out. Call google();

  5. #5
    Registered User
    Join Date
    Feb 2005
    Posts
    13
    Here is 2 problems I have that I'm having trouble with. I'm reading about pointer and having a hard time understanding how they work. Here is 2 problems were I need to figure out what will print out.

    Code:
    int n1 = 100; /* assume n1 is at address 10240 */
    int n2 = 150; /* assume n1 is at address 10244 */
    int *p = &n1; /* assume n1 is at address 10248 */
    printf("%d -- %d\n", &n1, n1);
    printf("%d -- %d\n", &n2, n2);
    printf("%d -- %d -- %d\n", &p, p, *p);
    p++;
    printf("%d -- %d -- %d\n", &p, p, *p);
    
    ----output -----
    
    10240 -- 100
    10244 -- 150
    10248 -- 10248 -- 100
    10252 -- 10252 -- 100
    
    ----------------
    
    
    
    int list[] = {3, 9, 6};   /* assume list is at address 10240 */
    int n = 150;             /* assume n is at address 10252 *
    int *p = list           /* assume n1 is at address 10256 */
    printf("%d -- %d\n", &list[0], list[0]);
    printf("%d -- %d\n", &list[1], list[1]);
    printf("%d -- %d\n", &list[2], list[2]);
    printf("%d -- %d\n", &n, n);
    printf("%d -- %d -- %d\n", &p, p, *p);
    p++;
    printf("%d -- %d -- %d\n", &p, p, *p);
    p = list;
    printf("%d -- %d\n", (p + 1), *(p + 1));
    printf("%d -- %d\n", (p + 2), *(p + 2));
    printf("%d\n", p + 1, *p + 1);
    
    ----output -----
    
    10240 -- 3
    10241 -- 9
    10242 -- 6
    10252 -- 150
    10240 -- 10240 -- 3
    10260 -- 10260 -- 7
    4 -- 10257
    5 -- 10258
    4 -- I don't know
    
    ----------------
    Am I close to having the right answers, I've read the chapter twice and still don't understand pointers.

    Shane

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >I just thought it would be easier dealing with on person
    Easier perhaps, but unless your mentor is a C god, it's unlikely that they'll be correct all of the time. Posting your questions on a public forum guarantees that if someone makes a mistake, they can be corrected before it hurts you.

    >I've read the chapter twice and still don't understand pointers.
    Pointers are simple in theory. There are three parts to a pointer:

    - An address
    - A value
    - A dereferenced value

    The address of a pointer is just like the address of any other variable. The value of a pointer is the address of another variable, which may or may not be another pointer. The dereferenced value of a pointer is the value contained by the value of the pointer:
    Code:
    #include <stdio.h>
    
    int main ( void )
    {
      int a = 10;
      int *p = &a;
    
      printf ( "%p -- %p -- %d\n", (void *)&p, (void *)p, *p );
    
      return 0;
    }
    What makes pointers seem complicated is that you can combine those three parts to give yourself a great deal of flexibility. Most people also have trouble wrapping their minds around a three tier definition.
    My best code is written with the delete key.

  7. #7
    Registered User
    Join Date
    Mar 2005
    Posts
    11
    Quote Originally Posted by scarr105
    Am I close to having the right answers, I've read the chapter twice and still don't understand pointers.
    Shane
    When I first started messing with pointers I had one heck of a time getting my head around them. A friend helped me out this way...

    "Ok, you're invited to a party.... How do you know where to go?"
    "I have the address"...
    "Where is the address?"
    "On the invitation."
    "So the invitation is a pointer to the party."

    Same concept in C... a pointer holds the address of a variable in the same way an invitation holds the address of the party.

    int *X;
    Is a pointer to an integer... the invitation.

    Y = &X;
    Answers the question "where is the invitation?"... it returns the address of X.

    Z = *X;
    Invites the people at the party to a new location... the data at the address pointed to by X is copied to Z.

    With this in mind, try reading the chapter on pointers again...

  8. #8
    Registered User
    Join Date
    Feb 2005
    Posts
    13
    The problem with the book we have is it's a reference book so they don't explain things very good. I understand the the address examle but the problem I have still makes no sense to me.
    Code:
    int n1 = 100; /* assume n1 is at address 10240 */
    int n2 = 150; /* assume n1 is at address 10244 */
    int *p = &n1; /* assume n1 is at address 10248 */
    printf("%d -- %d\n", &n1, n1);
    printf("%d -- %d\n", &n2, n2);
    printf("%d -- %d -- %d\n", &p, p, *p);
    p++;
    printf("%d -- %d -- %d\n", &p, p, *p);
    
    ----output -----
    
    10240 -- 100
    10244 -- 150
    10248 -- 10248 -- 100
    10252 -- 10252 -- 100
    
    ----------------
    the 2 parts that don't make sense is
    printf("%d -- %d -- %d\n", &p, p, *p);
    p++;
    printf("%d -- %d -- %d\n", &p, p, *p);

    &p = the address of p
    *p is the value
    what is p?

  9. #9
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Let's remove some assumptions...
    Code:
    #include <stdio.h>
    
    int main( void )
    {
       int n1 = 100;
       int n2 = 150;
       int *p = &n1;
       printf("&n1 = %p, n1 = %d\n", (void*)&n1, n1);
       printf("&n2 = %p, n2 = %d\n", (void*)&n2, n2);
       printf("&p  = %p, p  = %p, *p = %d\n", (void*)&p, (void*)p, *p);
       p++;
       printf("&p  = %p, p  = %p, *p = %d\n", (void*)&p, (void*)p, *p);
       return 0;
    }
    
    /* my output
    &n1 = 0012FF88, n1 = 100
    &n2 = 0012FF84, n2 = 150
    &p  = 0012FF80, p  = 0012FF88, *p = 100
    &p  = 0012FF80, p  = 0012FF8C, *p = 1245112
    */
    Oops, the last attempt appears to make some assumptions it outght not. An improved version might be...
    Code:
    #include <stdio.h>
    
    int main( void )
    {
       int n[] = {100, 150};
       int *p = n;
       printf("&n[0] = %p, n[0] = %d\n", (void*)&n[0], n[0]);
       printf("&n[1] = %p, n[1] = %d\n", (void*)&n[0], n[0]);
       printf("&p    = %p, p = %p, *p = %d\n", (void*)&p, (void*)p, *p);
       p++;
       printf("&p    = %p, p = %p, *p = %d\n", (void*)&p, (void*)p, *p);
       return 0;
    }
    
    /* my output
    &n[0] = 0012FF84, n[0] = 100
    &n[1] = 0012FF84, n[1] = 100
    &p    = 0012FF80, p = 0012FF84, *p = 100
    &p    = 0012FF80, p = 0012FF88, *p = 150
    */
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  10. #10
    ---
    Join Date
    May 2004
    Posts
    1,379
    Get it right or your going to confuse the poor guy
    Code:
    int *X;
    //Is a pointer to an integer... the invitation.
    
    X = &Y;
    //Answers the question "where is the invitation?"... it returns the address of Y.
    
    Z = *X;
    //Invites the people at the party to a new location... the data at the address pointed to by
    //X is copied to Z.

  11. #11
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    Quote Originally Posted by Prelude
    >Easier perhaps, but unless your mentor is a C god
    lol. i first read that as "unless your mentor is cgod".

    is that dude even still around?
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  12. #12
    ---
    Join Date
    May 2004
    Posts
    1,379
    He comes back every now and then to give us a good laugh.
    (Actually that's exactly what I thought at first glance too lol)

  13. #13
    Registered User
    Join Date
    Mar 2005
    Posts
    11
    Quote Originally Posted by sand_man
    Get it right or your going to confuse the poor guy
    Code:
    int *X;
    //Is a pointer to an integer... the invitation.
    
    X = &Y;
    //Answers the question "where is the invitation?"... it returns the address of Y.
    
    Z = *X;
    //Invites the people at the party to a new location... the data at the address pointed to by
    //X is copied to Z.
    ummmm... you do realize I was working through a metaphor, not trying to write working code.

    What confuses most students is seeing their teachers argue. What I said was NOT incorrect and reversing a couple of letters doesn't make it more correct.

    My suggestion was, and still is, that he re-read the chapter on pointers with my friend's metaphor in mind.

    Geesh!

  14. #14
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >you do realize I was working through a metaphor
    Metaphors have a tendency to break down at the worst possible time.

    >What I said was NOT incorrect
    Assmptions would have to be made to verify whether it was correct or not. For example, is Y a pointer? What you said could have been incorrect because it wasn't complete.

    >What confuses most students is seeing their teachers argue.
    However, teachers make mistakes. Would you rather a student be confused briefly when one teacher corrects another, or be given false information and believe that it's correct? That's precisely why I recommended not getting a single mentor.

    >Geesh!
    Get over it. We're a bunch of anal pedants around here. Either be as accurate as possible in your posts, or be prepared to defend any nitpicking with good reasoning.

    >i first read that as "unless your mentor is cgod".
    My best code is written with the delete key.

  15. #15
    Registered User
    Join Date
    Mar 2005
    Posts
    11
    Quote Originally Posted by Prelude
    Get over it. We're a bunch of anal pedants around here. Either be as accurate as possible in your posts, or be prepared to defend any nitpicking with good reasoning.
    Just follow the metaphor...

    X is the invitation, which points to the party ... int *X

    The question in the second part was "Where is the invitation" .. in the metaphor X is the invitation, therefore we want it's location ... Y = &X

    In the final bit we wanted to access the people at the party... and get them to a new location... Z = *X

    Your "correction" to the second part .. X = &Y ... didn't answer the question posed. It invited the guy to a whole different party.

    Oh and the way you presented it as though it was source code adding the // quote markers was a nice touch too... I was presenting a metaphor to help the OP undersand pointers, not trying to write a working program.

    Not very good reasoning for a self-confessed bunch of anal pendants!
    Last edited by ldblake; 03-23-2005 at 07:00 AM.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C Mentor Wanted
    By crypto_quixote in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 01-07-2007, 10:09 PM
  2. Looking for a mentor, of sorts
    By Mindphuck in forum C Programming
    Replies: 19
    Last Post: 04-04-2006, 03:23 PM
  3. Resource ICONs
    By gbaker in forum Windows Programming
    Replies: 4
    Last Post: 12-15-2003, 06:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21