Re: Vargr and Zhodani word generator souce code

By Dave Boddie ·

TML message #2432From bundle 201

+>by Juergen Kirsch:

+>Hello out there,
+>first thanks to Dave Boddie [email removed] for his Vargr and
+>Zhodani word generators. I got the sources yesterday and they run (after
+>some slight problems 8-).

I am not a very good programmer, particularly because I have been teaching
myself C, so I will try to answer this reply taking into consideration your
criticizms. I really need the criticizm, so fire away... This is a learning
experience for me... :)

+>I made some changes to get them started. Both sources are similar. The
+>problems and changes I've made are the same in both sources:

+>Problem 1:

+>> char *string[6], *wordstring;

+>In this line the declaration should be

+>char *string[7], *wordstring;

+>because you nead string[6] to create a pointer on a char variable which
+>contains the NULL delimiter if using 6 syllables.

I thought I had already compensated for that. Since all arrays in C begin at 0,
if you were to have 6 syllables, that would contain the elements 0-5, with the
6th element being the terminating char '\0'. Of course with the loop, if you
ended up with less than 6, the \0 would be placed wherever the end of the number
of syllables would lie.


+>Problem 2:
+>You had to complete the following line:

+>> string[i] = '\0';

+>by:
+>string[i] = malloc(sizeof(char));
+>*string[i] = '\0';

+>That's the only component of string[i] which needs memory seperatly. In the
+>loop above this line, the pointers of the variable "string" are set to the
+>entries of the tables "alt" and "basic". So no allocation of memory is needed.

Why would you have to do this? I figured since I defined string[6], there would
be space allocated for it. I do admit I didn't do this, but I saw no reason to
allocate extra memory for a string terminator.


+>Problem 3:

+>I had some trouble with the random generator used. I have compiled the program
+>with Borland TurboC Version 2.0. The random generator included there
+>generates random numbers ranged 0..max-1 if you call random(max).
+>The random generator in the sources generates numbers ranged 1..max.
+>Make sure your random generator works in the correct range. The tables
+>of vowels and consonants need ranges of 0..5. The functions GetICons etc.
+>need ranges of 1..6. The variable "syllables" should also assume values
+>from 1 to 6.

I am also using TurboC v2.0 also. In the beginning, I thought about generating
a 0-max-1 or 0-5 range, but thanks to personal preferences, I decided to go
with the 1-6 range and change it later. In the GetICons and other functions,
I reduced the random number generated by one whenever I went to reference
anything from the array tables. THat gave me a 0-5 range (I know it's not
truly random, but what the heck...I reduced all the values of my random
generated variablse by 1 whenever accessing an array. I think it was mostly
preference than anything...I tested it here, and it came out fine.


+>The results produced by the original were unusable and can't be spelled.

Hmmmmm. This seemed to work for me...it follows the rules laid down in the
Alien Modules for creating words. If you will look in the Vargr alien module,
you will notice some of those words do gain an excess of 15+ letters, and
are sometimes hard to pronounce. I believe in my next indever (unless some
one wants to help me -- hint, hint) I will add a pronounciation to the word
generator.

+>If someone has better ideas for correcting the source, please send me
+>a notice.

Yes, please do...this is pretty fun to get critiqued....

+>Juergen
+>Institut fuer Informatik der Universitaet Bonn
+>Bonn, Germany
+>[email removed]

Dave Boddie
- - --
========================Greetings from the Flux==========================
:                       Using Elm revision 64.9                         :
: Dave Boddie                                          ___________      :
: Computer Operator I / Lab Consultant                 |+         |_    :
: University of Arkansas, Fayetteville                 | NorthWest /    :
: Bitnet: [email removed]                              | Arkansas |     :
: Internet: [email removed]                            |_ U of A /      :
:                                                        |______|       :
:    "Strive for exellence, struggle for power, grieve for losing."     :
=========================================================================