Re: [Dev-C++] Producing a endless list of strings.
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <ten...@ne...> - 2003-07-30 17:58:45
|
First, I don't want to be exhaustive, here, but I say what I think right
know.
In a trial I did about filling areas of same color with one I selected
it crashed, in the one I checked the number of recursions performed in
the 57th, the function had seven parameters: two passed by value, two
were pointers and the other three passed by reference.
With a loop it didn't only work fine, but very faster (the loop version
filled a, say as any number, surface of 50 * 50 pixels in one minute and
some seconds, the loop version filled all the screen (800*640) in less
than a second).
I see hard how to do what you want recursively.
I would do a loop like this:
char list[1000][101]; <- I hope these are correctly done: 1000 strings
with 100 chars plus the null
for (int i = 0; i < number_of_strings; i++){
for (int j = 0; j < number_of_chars && list[i][j-1] != '\0'; j++){
list[i][j] = (the number you assign it as you want, as you calculated it
before or here I don't achieve to understand exactly what mean steps 2
and 3.)
if (list[i][j] == 127)
do the transformation you want.
} // second for
}//first for
P.D. - The access violations can be caused by the fact you don't
allocate memory for the pointers you use, if you use them as pointers,
not as statically allocated array, which is what I do inthis piece.
David McKen wrote:
>Ok, this is not a school assignment so please don't ask.
>
>I would like to produce a list of null terminated strings
>that I plan to use to test a hash function. Unfortunately I
>am a bit stumped as what would be the best way to create
>such a list.
>
>The algorithm is as follows:
>1. Start with a string containing only a space.
>
>2. Increment the first character in the string.
>
>3. If the value of the first character is 127 (DEL) then
>set it to 32 (space) and increment the next character
>(repeat this step if that character is 127).
>
>4. print out the string.
>
>5. goto step 2.
>
>I know, Recursion is screaming at me to use it.
>Problem is, how? I am getting stuck in the wind-up section.
>(That and the fact that Visual C++ is giving me access
>violations)
>
>My other question is, does anyone else know another way?
>Eventually I hope to use this to create strings at least
>100 chars long (possibly 1000). Could someone tell me if
>100 levels using recursion cause a stack overflow?
>
>Thanks in Advance
>David Mcken
>
>__________________________________________________
>Do you Yahoo!?
>The New Yahoo! Search - Faster. Easier. Bingo
>http://search.yahoo.com
>
>
>-------------------------------------------------------
>This SF.Net email sponsored by: Free pre-built ASP.NET sites including
>Data Reports, E-commerce, Portals, and Forums are available now.
>Download today and enter to win an XBOX or Visual Studio .NET.
>http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
>_______________________________________________
>Dev-cpp-users mailing list
>Dev...@li...
>TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
>https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
>
>
|