convert 2D array into 1D array

This is a discussion on convert 2D array into 1D array within the C Programming forums, part of the General Programming Boards category; plz send me the source code for converting an array in 2Dimension into a 1Dimensional array..i need it for further ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    9

    Unhappy convert 2D array into 1D array

    plz send me the source code for converting an array in 2Dimension into a 1Dimensional array..i need it for further application in generalising it for N dimensions..
    plz help..

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    We don't do other people's work for them. We'll be happy to help you devise a solution though, if you can provide more information and describe what you've already tried.
    My best code is written with the delete key.

  3. #3
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    a thought for you.... a multi dim array is pretty sequential in memory. You could spend a minute thinking about how they might do that. Then implement it in code.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >a thought for you.... a multi dim array is pretty sequential in memory.
    Pretty sequential, but not necessarily exactly sequential. A multidimensional array is an array of arrays, and each array is independent. So any extra "stuff", transparent to the programmer, that an array has will exist in each subarray of a multidimensional array. This means that treating a multidimensional array as a one dimensional array is inherently non-portable. Be wary of that solution.
    My best code is written with the delete key.

  5. #5
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    yeah, I hadn't thought that he might go that direction (casting it or something). Actually, I was thinking more along the lines of doing the math to get the right index in a single dim. Good catch P.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. question about multidimensional arrays
    By richdb in forum C Programming
    Replies: 22
    Last Post: 02-26-2006, 08:51 AM
  2. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM
  3. how to pass 2D array into function..?
    By IngramGc in forum C++ Programming
    Replies: 2
    Last Post: 10-21-2001, 08:41 AM
  4. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM
  5. 2d Array access by other classes
    By deaths_seraphim in forum C++ Programming
    Replies: 1
    Last Post: 10-02-2001, 08:05 AM

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