Davion,
Great questions!
>whats stristr do?
Stristr is a case-insensitive strstr. I added the code to the file
since it isn't standard. And you are absolutely correct with what you
said--the code I submitted using stristr would not work as planned if
there were two players such as 'Raine' and 'Tamraine'. What you could
do, then, is use strstr:
char name[MIL];
//Guarantees name is full of NULLs so you can use strcat safely
#include <string.h>
memset(name, 0, MIL);
//can also do:
#include <strings.h>
bzero(name, MIL);
name[0] = ' ';
strcat(name, ch->name);
strcat(name, " ");
This could get you a search string of " Raine ". This would not run into
any collision problems with " Tamraine ". It's not "better" persay than
using a pointer pointer char array, but it simplifies memory management.
So to add a new guesser, it'd be:
strcat(wordtwist.guessers, ch->name);
strcat(wordtwist.guessers, " ");
Your guesser string would look like:
" Raine Tamraine Fish Dog Cat "
As one last note, you'd have to start the string off with a space in the
reset function.
As for return points:
This is a general programming technique oriented toward projects that
many people work on. The problem with numerous points of exit is
something like using gotos--the code can be difficult to track,
especially for other team members in your team trying to read your
code. It also is very easy to miss a condition and fail to always
return a value from a function. This will prevent that error.
Davion Kalhen wrote:
To Mr. Potatohead:
alloc_perm() makes calls to calloc, I also believe that the chunk
memory is calloc'd too.
To Jeremy:
Just a couple questions outta curiosity... whats stristr do? I checked
my man files, but nothing came up! If it works like strstr, then
wouldn't you have a problem if you had a word thats part of another? I
can't come up with one atm.. oh! A word that starts with 'a' and ends
with 's', Alias, Aliases. Heh if thats even spelled right :P. Thats
why I'd think str_cmp is better. I've used a system kinda like that
for quests and such, I store them <13> like that, so I can strstr for
the number with brackets around it to avoid such a problem.
Also...
//A good function only has 1 return point if possible.
Why? I dun get why? Is it for compiling time? Saves... memory? Or is
it just what has been deemed?
Davion