Thread: Nulling an array

  1. #16
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    But I like that struct initializing method instead of calling in a function, how do I use that for modifying just one specificied member? Tried nulling the remaining members but some are arrays with pointers and it gives all sorts of errors
    =========================================
    Everytime you segfault, you murder some part of the world

  2. #17
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    And that's presumably the size of the array?

    You can't do that. Initialization like was suggested early on in this thread is ONLY possible when you declare the variable itself.

    If, inside the code, you need to fill the array with a value (such as zero), then memset is the option.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #18
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    Ah memset, that seemed to work, thanks !
    =========================================
    Everytime you segfault, you murder some part of the world

  4. #19
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,653
    Quote Originally Posted by JFonseka View Post
    A is #defined to be 50
    Boom! Buffer overflow!
    You are using the index operator to access the 51th element there. And ONLY that element to boot, nothing else.
    Be careful with those arrays! Buffer overruns are very bad.
    All arrays goes from 0 to size - 1.
    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.

  5. #20
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    Quote Originally Posted by Elysia View Post
    Boom! Buffer overflow!
    You are using the index operator to access the 51th element there. And ONLY that element to boot, nothing else.
    Be careful with those arrays! Buffer overruns are very bad.
    All arrays goes from 0 to size - 1.
    Yea well in my program I didn't have it as 50, I had it at 1000, I was just using random numbers, lol.
    =========================================
    Everytime you segfault, you murder some part of the world

  6. #21
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,653
    OK, so you avoided a buffer overrun. That's good
    But using random numbers everywhere doesn't make much sense, does it?
    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.

  7. #22
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    Quote Originally Posted by Elysia View Post
    OK, so you avoided a buffer overrun. That's good
    But using random numbers everywhere doesn't make much sense, does it?
    I just gave it 1000 because I knew there was no way 1000 elements would be used
    =========================================
    Everytime you segfault, you murder some part of the world

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 10:33 AM
  3. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM