Page 1 of 1

How can I change strings value?

PostPosted: Sat Dec 18, 2010 10:40 am
by tzoli
Ithink it's a noob question but i can't do this

Re: How can I change strings value?

PostPosted: Sat Dec 18, 2010 11:17 am
by schnellboot
gimme an example

Re: How can I change strings value?

PostPosted: Sat Dec 18, 2010 11:29 am
by tzoli
I have a string.It's empty and I want to change this value.

Re: How can I change strings value?

PostPosted: Sat Dec 18, 2010 8:10 pm
by skydereign
If you have a null char*, you have to malloc it first.
Code: Select all
char * test; // it is null
test = malloc(255); // no longer null
strcpy(test, "text to go into the string here");


You can also use sprintf or any other str function. If it is a char[] then it should work without the malloc. But do make sure to free the char* after you don't need it anymore.

Re: How can I change strings value?

PostPosted: Sat Dec 18, 2010 8:11 pm
by tzoli
Thank you :)

Re: How can I change strings value?

PostPosted: Sun Dec 19, 2010 6:46 am
by tzoli
But i have an another problem... I want to read it and write in actor...But my code doesn't works...
Code: Select all
csak1ideig.text = file1;

Re: How can I change strings value?

PostPosted: Sun Dec 19, 2010 7:11 am
by skydereign
I assume that you want to read in a file, if so you will have to use fopen, and fgets. Here are some posts about how to use it.
http://game-editor.com/forum/viewtopic.php?f=1&t=8984&hilit=+fopen
http://game-editor.com/forum/viewtopic.php?f=2&t=6968&hilit=+fopen#p49662

Re: How can I change strings value?

PostPosted: Sun Dec 19, 2010 9:49 am
by tzoli
No-No...The file1 is name of string

Re: How can I change strings value?

PostPosted: Sun Dec 19, 2010 10:08 am
by skydereign
Oh, that's simple. All you would just use strcpy, or sprintf, and the "text to go into the string here" is replaced with the string (they are both strings).
Code: Select all
strcpy(text, file1);