3 registered members (NewbieZorro, TipmyPip, 1 invisible),
19,045
guests, and 8
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
listing strings in rows/Liste aus Strings
#132580
05/29/07 19:05
05/29/07 19:05
|
Joined: May 2007
Posts: 19
Zalon
OP
Newbie
|
OP
Newbie
Joined: May 2007
Posts: 19
|
Hi Board,
I like to create a kind of ingame address book, showing the addresses the player collected in some rows and add a function to filter the entries later on.
That's the idea, but it seems I've done something terribly wrong, as there are massive problems occuring, including some crashes of the editor.
Maybe somebody's having a good idea or some code-snippets?
What I've coded yet:
First of all, I created a struct that will contain the names and addresses. Simplified, this struct looks like this: struct { char name; char street; var number;} data; DATA* addressbook;
Storing some information using addressbook.name, addressbook.street = etc.. was simple.
To display the information onto the screens, I defined some TEXT*-panels, one for the row of names, one for the row of streets etc. So there are three strings now, called name_string, street_string, number_string.
Now I wanted to copy the information out of the struct into the strings, seperated by "\n" for the new lines, having a string for each row.
But that didn't work. name_string = addressbook.name as a test will crash the editor.
My first idea, to use a while-loop doesn't work either.
while(i) name_string = str_cat(name_string, addressbook.name);
I've got that feeling, that there has to be a much easier way...
So any help will be appreciated!! Thanks!
---------------------
Hallo,
ich möchte gerne ein Ingame Adressbuch erstellen, bei dem dem Spieler die bereits gefundenen Orte und Personen in Reihen aufgelistet werden. Später soll eventuell eine Filterfunktion dazukommen. Soweit die Idee, jedoch scheine ich da etwas falsch zu machen.
Ich hoffe dass mir jemand mit einer guten Idee oder ein paar Zeilen Code weiterhelfen kann.
Bisher habe ich folgendes gemacht:
Als erstes habe ich eine Struct erstellt, in der die Namen und Adressen gespeichert werden sollen. Vereinfacht ausgedrückt, sieht diese so aus:
struct looks like this: struct { char name; char street; var number;} data; DATA* addressbook;
Die Informationen mittels addressbook.name, addressbook.street = etc.. einzuspielen war kein Problem.
Um später die Adressen in Reihen ausgeben zu lassen, habe ich drei TEXT*-panels, pro Reihe eine, erstellt. Die dazugehörigen Strings, name_string, street_string, number_string, habe ich auch definiert.
Jetzt wollte ich die Informationen aus der Struct in die Strings kopieren, jeweils mit einem Zeilenumbruch getrennt. Damit hätte ich dann pro Reihe einen String.
Aber das funktioniert bislang nicht.
name_string = addressbook.name als Testversion bringt den Editor zum Absturz.
Auch meine erste Idee, eine While-loop zu nutzen klappt nicht.
while(i) name_string = str_cat(name_string, addressbook.name);
Ich habe das Gefühl, es muss auch einfacher gehen... Für Hilfe bin ich dankbar!
Last edited by Zalon; 05/29/07 19:15.
|
|
|
Re: listing strings in rows/Liste aus Strings
[Re: jcl]
#132582
05/31/07 14:14
05/31/07 14:14
|
Joined: May 2007
Posts: 19
Zalon
OP
Newbie
|
OP
Newbie
Joined: May 2007
Posts: 19
|
Thanks for the reply.
I already used debugger and breakpoints but couldn't find a solution.
Maybe a dumb question, but char name [32] will create an array (in the struct??), won't it? Will that solve my problem of crashes while transforming them into strings? (and if it does: why?)
Is there a way to define strings in the struct? Obviously struct {string test} does not work...
Whew, quite many questions. Hope you (or anyone else?) might help.
Last edited by Zalon; 05/31/07 14:29.
|
|
|
Re: listing strings in rows/Liste aus Strings
[Re: FBL]
#132584
05/31/07 19:46
05/31/07 19:46
|
Joined: May 2007
Posts: 19
Zalon
OP
Newbie
|
OP
Newbie
Joined: May 2007
Posts: 19
|
Thanks. That means, by defining an array of chars, I create a string?
I'm always wondering where to find thie kind of information, neither the Lite-C tutorial, nor the SED-manual deal with such things...
Last edited by Zalon; 05/31/07 19:49.
|
|
|
Re: listing strings in rows/Liste aus Strings
[Re: Zalon]
#132585
05/31/07 21:43
05/31/07 21:43
|
Joined: Sep 2003
Posts: 9,859
FBL
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 9,859
|
You create a string as defined in standard C - but an A6 STRING is an own struct which carries some more information. Use str_create("...") to create an A6 STRING. A6 string function like str_cpy or str_cat (note the _) expect as target a STRING and as source a ponter to a char array or a STRING as well. For copying around char arrays you'll need to add your own APIcalls for strcpy, strcat, strlen... This is what the A6 STRING struct looks like. The char array is referenced by "chars": Code:
typedef struct STRING { C_LINK link; char *chars; // pointer to null terminated string long length; // allocated length of string long flags; // last bit 0 = don't save, 1 = save string at SAVE/LOAD } STRING;
|
|
|
Re: listing strings in rows/Liste aus Strings
[Re: FBL]
#132586
06/01/07 13:24
06/01/07 13:24
|
Joined: May 2007
Posts: 19
Zalon
OP
Newbie
|
OP
Newbie
Joined: May 2007
Posts: 19
|
Thanks again my friend.
Thing I got that: A A6 string is a kind of char.
But I still don't understand the link between the string definiton and a char array. Why should I change my own struct definition to include char arrays instead of pure chars?
Additionally you mentioned another point. You wrote, I'll have to add my "own APIcalls for strcpy, strcat...".
First of all, just to see whether I really understand you: As A6's strings are something special and these functions expect not only a string but a special form, namely a "A6 string", they wouldn't work with a "normal" (that means a standard C) string. Is that right?
But as I should deal with char-arrays (see above, I still don't get the why), I have to find a way to rewrite these functions to accept these inputs..?
To make things worse, I have no idea how to change the APIcalls as I don't even know how they look like. I'll have a look at the manual immediately, maybe there are some hints concerning these ominous calls, but just in the case I don't find something appropriate - in fact appropriate for me - how could I start here?
Phew. That's becoming real tough for me.
Last edited by Zalon; 06/01/07 13:27.
|
|
|
Re: listing strings in rows/Liste aus Strings
[Re: Zalon]
#132589
06/01/07 17:35
06/01/07 17:35
|
Joined: Sep 2003
Posts: 9,859
FBL
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 9,859
|
structs can contain STRINGs. This is no problem.
As to your copy problem:
struct test{ char charArray[5]; };
STRING mySTR; struct test testCharStruct; mySTR = str_create("");
testCharStruct.charArray[0]= 't'; testCharStruct.charArray[1]= 'e'; testCharStruct.charArray[2]= 's'; testCharStruct.charArray[3]= 't'; testCharStruct.charArray[4]= '\0'; /*string termination*/
str_cpy(mySTR, testCharStruct.charArray);
printf("%s", mySTR->chars);
untested. Probably won't work because I did some stupid mistake... but I hope you get the idea.
Last edited by Firoball; 06/01/07 17:41.
|
|
|
|