TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: THOMAS HABETS
from: MIKE LUTHER
date: 1998-02-08 19:08:00
subject: Re: Help with multi-dim chara

Thanks for your thoughts Thom.. 
 
 > TH:  ML>  DIM K$(100) AS STRING * 256 
 
 > TH: Uh, you mean like: 
 > TH: char K[256][100]; 
 
       Yep...  which works fine... in WATCOM C++ 
       Do compile and declare just fine. 
 
 > TH:  ML>  PRINT K$(2) 
 > TH:  ML>  PRINT K$(4) 
 > TH: cout << K[2] << "\n"; 
 > TH: cout << K[4] << "\n"; 
 
       Which works fine in WATCOM C++ 
 
 > TH:  ML>  END 
 > TH: exit(0) :-) 
 
       Sure.  :) 
 
 > TH:  ML>    FOR NZ = 1 TO 99 
 > TH:  ML>      INPUT #3, K$(NZ) 
 > TH:  ML>  RETURN 
 > TH: for (c = 1; c < 100; c++) 
 > TH:     cin >> K[c]; 
 > TH: return 
 
      Which works fine in WATCOM C++  in MAIN... 
 
      until... 
 
      You try to do the loop in a FUNCTION... 
 
Suppose I want to move the loop to a function that does lots of things inside 
it to the various character arrays [x][100].  Then I wish to report back out 
from the function what all the master array had done to it. 
 
I can't get the array of character arrays passed to the function and extract 
any data back from the function.  It all works just fine so long as all the 
code is in MAIN.  However, as fast as you, for example, try to bury the 
 
       for (c = 1; c < 100; c++) 
           cin >> K[c]; 
 
in the function, when you call the function from MAIN, no matter what you try 
to tell the compiler is a pointer or a pointer to a pointer, it refuses to 
compile that statement!  Either the error will be "Must be a pointer to a 
Character", or if you do that, the error is "Does not match the arguement in 
the Prototype."  You're damned if you do and damned if you don't!  :) 
 
What happens is that you seemingly can't carry the double dimension into the 
function!  That, violates the agreement that it is, technically, impossible 
to care a multi-dimensional array into a function and pass data from the 
function back into main... 
 
You, apparently can have a pointer to anything, but not necessarily pass data 
as anything..  :) 
 
So far, from discussion here and reading advanced books, I think I understand 
that the only thing we can use with which to communicate with a function is a 
single pointer to the first of a segment of memory, a linear block of memory. 
 All I can do is point to the start of that block and then pass the entire 
block of characters, which includes all the sub-elements of character arrays 
to the function at call time.  Then, I seemingly have to write all my own 
code to pick apart characters from inside the main array, as needed, and set 
them to the individual elements in or out of the 'array'... 
 
That, I think I understand, C++ will do.  Once inside the function, or in 
main, my only choice is to use an offset to the nth element (a subset of the 
whole character array that is holding this data), then step, as needed into 
that offset plus a sub-offset, to work with the exact data. 
 
That poses another problem.  In that a string in C or C++, is merely an array 
of characters, terminated with a null, if I *DO* use a master array of 
characters containing more arrays of characters in a block array, I can't 
actually dare pass the end null characters of the individual elements into 
the master array during the call or the extract from the call.  If I do, 
there will be embedded nulls in the master array which more or less 
conventional C/C++ 'string' handling routines cannot handle; they are 
thwarted by the embedded nulls... 
 
   ********* 
 
Of course, we haven't really even started on the next step here... 
 
     How to do all this for ragged length string arrays..., using 
     what I am now learning are Illeff vectors et. al. :( 
 
Mike @ 117/3001 
--- Opus-CBCS 1.73a
---------------
* Origin: Ziplog Public Port (1:117/3001.0)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.