Thread: Structure help?

  1. #1
    Registered User
    Join Date
    Sep 2010
    Location
    Boston, MA
    Posts
    97

    Structure help?

    So im still very new to C programming, i just got into structures, I have a quick question.

    My structure consists of 5 doubles and an array of ints. How would you zero all of them the easiest?

  2. #2
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    memset(&structname, 0, sizeof(structname))

  3. #3
    Registered User
    Join Date
    Sep 2010
    Location
    Boston, MA
    Posts
    97
    thanks

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    You should note that
    memset( &myfloat, 0, sizeof(myfloat) );
    does not necessarily guarantee that myfloat is 0.0
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    static struct foo blank;
    struct foo instance;
    
    instance = blank;
    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Structure within a Structure
    By JJohnson in forum C Programming
    Replies: 16
    Last Post: 12-18-2010, 12:45 PM
  2. Replies: 1
    Last Post: 05-18-2010, 04:14 AM
  3. Problem Passing Structure Reference To Function
    By soj0mq3 in forum C Programming
    Replies: 9
    Last Post: 04-24-2010, 10:27 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM