Structure help?

This is a discussion on Structure help? within the C Programming forums, part of the General Programming Boards category; So im still very new to C programming, i just got into structures, I have a quick question. My structure ...

  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,831
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,420
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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, 11:45 AM
  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, 09:52 AM

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