Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by AndrewAMD. 12/05/23 10:56
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
6 registered members (AndrewAMD, alibaba, fairtrader, ozgur, TipmyPip, Quad), 622 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
char* to char* #112935
02/21/07 09:17
02/21/07 09:17
Joined: Jul 2006
Posts: 783
London, UK
sheefo Offline OP
User
sheefo  Offline OP
User

Joined: Jul 2006
Posts: 783
London, UK
How can I copy the contents of a char* to another char*? Since they are pointers, when the source char* changes, so does the destination char*.

Is there a function to do this? I have tried all sorts of 'memset' stuff but they didn't work.

Re: char* to char* [Re: sheefo] #112936
02/21/07 09:46
02/21/07 09:46
Joined: Apr 2005
Posts: 3,815
Finland
Inestical Offline
Rabbit Developer
Inestical  Offline
Rabbit Developer

Joined: Apr 2005
Posts: 3,815
Finland
they are the same datatype, so operator function '=' is fine.

char* foo = "temporary";
char* bar;

...
bar = foo; // bar is now "temporary"
...


"Yesterday was once today's tomorrow."
Re: char* to char* [Re: Inestical] #112937
02/21/07 10:51
02/21/07 10:51
Joined: Jul 2006
Posts: 783
London, UK
sheefo Offline OP
User
sheefo  Offline OP
User

Joined: Jul 2006
Posts: 783
London, UK
It doesn't work because I want my char* to point to the 'temp_string->chars' which is a char*. Whenever I edit 'temp_string', which is a million times a frame, it will change my char*.

Re: char* to char* [Re: sheefo] #112938
02/21/07 10:55
02/21/07 10:55
Joined: Jan 2004
Posts: 2,013
The Netherlands
E
Excessus Offline
Expert
Excessus  Offline
Expert
E

Joined: Jan 2004
Posts: 2,013
The Netherlands
No it doesn't change your char*, it changes the char array that it is pointing to.. What you want is probably to make a copy: str_cpy()..

Re: char* to char* [Re: Excessus] #112939
02/21/07 12:37
02/21/07 12:37
Joined: Jul 2006
Posts: 783
London, UK
sheefo Offline OP
User
sheefo  Offline OP
User

Joined: Jul 2006
Posts: 783
London, UK
I get invalid argument error when I use 'str_cpy'. I remember in C++ there us a 'strcpy' (without the underscore) for using char*. This is what I need, but it isn't working under Lite-C. Is there a way to include this or do I have to make a plugin function?

Re: char* to char* [Re: sheefo] #112940
02/21/07 13:42
02/21/07 13:42
Joined: Jan 2006
Posts: 1,829
Neustadt, Germany
T
TWO Offline

Serious User
TWO  Offline

Serious User
T

Joined: Jan 2006
Posts: 1,829
Neustadt, Germany
I donīt know if C-Lite handles this like C, but this should work

char* foo = "Doener";
char* bar;

bar = *foo; // Note the *

Re: char* to char* [Re: TWO] #112941
02/21/07 13:59
02/21/07 13:59
Joined: Jul 2006
Posts: 783
London, UK
sheefo Offline OP
User
sheefo  Offline OP
User

Joined: Jul 2006
Posts: 783
London, UK
I have tried all of this before. Sometimes it turns out as giberish, with symbols and crap. I had no idea what I was doing in the end, I used "&" and "*" and "&*" but I get no real results.

The solution is to use a function like 'strcpy' in C. I think it was avaliable when you include <string> but I cannot do so in Lite-C. So I am f***ed.

Perhaps I should just make a DLL function in a plugin that will use 'strcpy'.

Re: char* to char* [Re: sheefo] #112942
02/21/07 16:06
02/21/07 16:06
Joined: Jul 2000
Posts: 27,967
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,967
Frankfurt
I guess you're confusing STRING* with char*.

A char* is a pointer to an array of chars, while a STRING is an engine object that contains chars.

The str_ functions are for strings, not for chars, although they also accept chars for the source argument. You can read in the manual about the string functions, and in any C book about char*, f.i. in the Sam's 21 days course.

The str_cpy engine function is for copying strings, and the C library strcpy function is for copying chars. Hope this helps.

Re: char* to char* [Re: jcl] #112943
02/21/07 17:56
02/21/07 17:56
Joined: Jan 2006
Posts: 1,829
Neustadt, Germany
T
TWO Offline

Serious User
TWO  Offline

Serious User
T

Joined: Jan 2006
Posts: 1,829
Neustadt, Germany
But why this doesn't work? It works in C++, why not in alight-C? O.o

Re: char* to char* [Re: TWO] #112944
02/21/07 19:50
02/21/07 19:50
Joined: Jul 2000
Posts: 27,967
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,967
Frankfurt
Well, it surely works if your intention was to get a happy crash . You've just overwritten your pointer with garbage.

What you all seem to be keen doing is not really beginner's stuff - it goes more in the 'real' C direction. This is not covered by the lite-C tutorial, which is meant for absolute beginners.

When you really want to get your hands dirty with pointers and so on, I recommend to read some about C basics before, as in the Sam's 21 days course. Here are some other links:

http://einstein.drexel.edu/courses/CompPhys/General/C_basics/c_tutorial.html#first

http://www.cprogramming.com/tutorial.html#ctutorial

http://www.lysator.liu.se/c/bwk-tutor.html

Fiddling with pointers and char arrays without really knowing what you're doing will quickly end in frustration. First comes the theory, then the fun.

Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1