[Crossfire-wiki] [Crossfire DokuWiki] page changed: user:mhoram:code:bwp

no-reply_wiki at metalforge.org no-reply_wiki at metalforge.org
Fri Jan 19 02:23:07 CST 2007


A page in your DokuWiki was added or changed. Here are the details:

Date        : 2007/01/19 02:23
User        : ryo
Edit Summary: stuff

@@ -29,8 +29,19 @@
  The way I read that, it looks like what I really want to pass to ''strcasecmp'' is a pointer to ''(char *)a'', but that doesn't work either.  (You can see that attempt commented out.)  I think for today I'm just going to comment out the ''qsort'' call so I can finish the rest of the program; in the meantime, any further hints on what I'm doing wrong would be much appreciated.
  
    * You need to do ''qsort(array->item, array->count, sizeof(char*), sortbyname);'', not ''qsort(array->item, array->count, array->longest, sortbyname);''. The item size is a char*, not the longest element. ''array->item'' is an array of ''char*'', that is of pointers to memory zones containing ''char'', not an array of items of size ''array->longest'' :) This can certainly explain some weird things.
      * I see what you're saying, but I was calling it that way in my ''qsort'' of ''archnames'', and that was working ok.  ''archames'' is an array of arrays, though, while ''array->item'' is a pointer to an array of pointers, so I ssupose that's the difference.  In any case, I think I have everything else working, so I've updated the code below.  ''sortbyname'' now no longer causes segfaults, but it still isn't sorting correctly either.  To be exact, it sorts ''archnames'' correctly, but not ''array->item''.  When I try <code>*(const char* *)a</code>, it segfaults, and when I inspect the variables with gdb, it says that's accessing a bad address.  At this point, I'm really stumped on this part, but I'm still looking for other examples.
+ 
+       * can you try with ''qsort(&array->item, ...)'' and the ''const char * ''? Not sure that's the issue, but well... Also a few hints:
+         * do ''canuse.count = 0;'' before using ''push''. Count isn't initialized, so weird effects can happen
+         * ''free(NULL)'' is perfectly correct in ANSI, i don't know what your debugger/compiler is complainign about :)
+         * instead of ''calloc(1, strlen(string)+1) / strncpy'', use ''strdup(string)'' in ''push'' (that's what this is for ^_-) - Crossfire may have a ''strdup_local'' somewhere, better use that if it exists
+         * doing ''char *newtext = "";'' is not required, and may be dangerous since you do ''realloc'' after (but of course you do ''calloc'', so the initialization won't do anything anyway ;p)
+         * for duplicated names, check if the monster isn't yet part of the array before inserting it
+         * it may be better to use ''archt* archetypes[4000]'' instead of ''char archnames[4000][MAX_SIZE];''. It would let you sort by name, then plural name, then archetype name in case of duplicated monsters, and also enable you to check for head/more
+         * similarly, you may want to avoid inserting archetypes which are ''more'' of another one - thus check ''more != NULL'' somewhere
+         * all in all, seems it'll work fine soon :)
+         * if you wanted to be really really flexible, you could use templates for flags themselves - instead of concatenating items with a comma, let a template (or a few, in this case) decide how to adjust stuff. This may be overkill, though, of course ^_-
  
  
  
  


IP-Address  : 196.3.55.241
Old Revision: http://wiki.metalforge.net/doku.php/user:mhoram:code:bwp?rev=1169177650
New Revision: http://wiki.metalforge.net/doku.php/user:mhoram:code:bwp

-- 
This mail was generated by DokuWiki at
http://wiki.metalforge.net/




More information about the crossfire-wiki mailing list