Thread: Structures in C

  1. #16
    Registered User
    Join Date
    Feb 2008
    Posts
    93
    The avg would print as the first number it obtained. Someone with no programming skills like myself would think if it were grabbing the first number it would divide the number by 5 because that's in the print statement.

  2. #17
    Registered User
    Join Date
    Feb 2008
    Posts
    93
    I am a dumb arse tabstop think you.

  3. #18
    * noops's Avatar
    Join Date
    Jun 2008
    Posts
    108
    I'm sure it is dividing by 5. But you are adding the first element to itself 5 times (your for loop).

    Logically, (5 * i) / 5 = i

    Change your 5 to a 12, or whatever, you'll see.

  4. #19
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Syntax lesson:
    t->grade is the same as (*t).grade.
    t->grade[i] is the same as *(t->grade + i).
    *t->grade is the same as t->grade[0].

    Remember: [] actually dereferences the pointer, so it's
    t->grade[i]
    and not
    *t->grade[i].

    Again, see above, and you'll see that your syntax keeps grabbing the first element all the time.
    You must do t->grade[i].
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. Structures within Structures
    By Misko82 in forum C Programming
    Replies: 2
    Last Post: 08-27-2007, 12:25 AM
  3. Structures, passing array of structures to function
    By saahmed in forum C Programming
    Replies: 10
    Last Post: 04-05-2006, 11:06 PM
  4. Structures, and pointers to structures
    By iloveitaly in forum C Programming
    Replies: 4
    Last Post: 03-30-2005, 06:31 PM
  5. Methods for Sorting Structures by Element...
    By Sebastiani in forum C Programming
    Replies: 9
    Last Post: 09-14-2001, 12:59 PM