Thread: Help with 2d arrays

  1. #16
    Registered User
    Join Date
    May 2008
    Posts
    19
    Quote Originally Posted by Elysia View Post
    You know how much data you're reading, aren't you? Then you know the width and height of your array.
    Actuauly no i don't know. Because the width and height keeps changing.
    my program will find find the width and height of the file. Bu the problem is i don't know how to specify the size of the resultant array.
    mabye i could do it this ay, but any ideas ?
    You could then have four variables: x_start, x_end, y_start, and y_end. When reading the array you would want to find these four points.

    When you are finished reading you could then crop the array to everything between these co-ordinates.

  2. #17
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Take it this way: you do read data into the array, so somehow you must know the size of the array and/or data, because otherwise you wouldn't be able to read it into the array, would you?
    Therefore we must logically assume that you know x_start, x_end, y_start, y_end of the array (and btw, x_start and y_start should be 0).
    Then you could basically read the array, find the data you want to keep and count that. From that information, you could create a new array and copy data over.
    It's not unlike any normal life situation, you just have to think over it logically. You can create a flow chart - a chart that describes how you want the process to be done, in terms of words.
    That's the first step of the process. After that, you translate it into code. But let's get the first part done first.
    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.

  3. #18
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Can you post a small example of how your data changes, requiring the array to change. Just something small, but something to help clarify your description.

    I don't have a clear enough picture yet, in my mind.

  4. #19
    Registered User
    Join Date
    May 2008
    Posts
    19
    Quote Originally Posted by Adak View Post
    Can you post a small example of how your data changes, requiring the array to change. Just something small, but something to help clarify your description.

    I don't have a clear enough picture yet, in my mind.
    hi there
    well all the files will have a variable width of 0 to 50, and a variable height of 0 to 80. But my program can find the height and width of the file. But the problem lies when i want to start to crop that array into a new array. i don't know the width and height of the new array as i can't open the file. the program will have to somehow find the row find the row that doen't contain all 0's in its column.
    hope that is enough information.
    thanks in advance

  5. #20
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by thamiz View Post
    i don't know the width and height of the new array as i can't open the file. the program will have to somehow find the row find the row that doen't contain all 0's in its column.
    But this is what we're telling you is so easy.
    If you traverse and read the array, you can determine how much data you need to copy.
    You have already demonstrated that you know how to traverse an array.
    The next step is to make sure the program remembers how much data it needs to copy.
    Then you can create a new array and copy the data over.
    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.

  6. #21
    Registered User
    Join Date
    May 2008
    Posts
    19
    Quote Originally Posted by Elysia View Post
    But this is what we're telling you is so easy.
    If you traverse and read the array, you can determine how much data you need to copy.
    You have already demonstrated that you know how to traverse an array.
    The next step is to make sure the program remembers how much data it needs to copy.
    Then you can create a new array and copy the data over.
    Would a counter be advisable

  7. #22
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Yes, a counter to count how many rows to copy might be advisable.
    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.

  8. #23
    Registered User
    Join Date
    May 2008
    Posts
    19

    thanks again for your patience and time

    Quote Originally Posted by Elysia View Post
    Yes, a counter to count how many rows to copy might be advisable.
    i have a question
    say if int a counter called goodrowcounter;
    when i int the array[goodrowcounter][width];
    my compiler say error: variable-sized objects may not be initialiased.
    what can i do to rectify this problem
    Last edited by thamiz; 05-25-2008 at 04:43 AM. Reason: typo

  9. #24
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by thamiz View Post
    i have a question
    say i int a counter called goodrowcounter;
    when i int the array[goodrowcounter][width];
    my compiler say error: variable-sized objects may not be initialiased.
    what can i do to rectify this problem
    You need to use malloc to create a dynamic array (don't forget to free it using free later either).
    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.

  10. #25
    Registered User
    Join Date
    May 2008
    Posts
    19
    Quote Originally Posted by Elysia View Post
    You need to use malloc to create a dynamic array (don't forget to free it using free later either).
    how do i use malloc

  11. #26
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Do you have a C book to learn from?
    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. 2D Array's, assigning chars.
    By gman89 in forum C Programming
    Replies: 9
    Last Post: 04-26-2008, 11:03 PM
  2. returning 2D arrays
    By ... in forum C++ Programming
    Replies: 2
    Last Post: 09-02-2003, 12:28 PM
  3. Initialising 2D and 3D arrays
    By fry in forum C++ Programming
    Replies: 5
    Last Post: 08-01-2002, 04:34 AM
  4. Reading 2d arrays from file?
    By Ringhawk in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2002, 09:05 PM
  5. how can i pass 2d arrays
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 11-02-2001, 07:33 AM

Tags for this Thread