How can I change strings value?

Non-platform specific questions.

How can I change strings value?

Postby tzoli » Sat Dec 18, 2010 10:40 am

Ithink it's a noob question but i can't do this
Creepers are capable of climbing ladders, despite lacking arms. (Minecraft wiki)
User avatar
tzoli
 
Posts: 343
Joined: Sat Jun 12, 2010 6:54 pm
Location: Behind you
Score: 15 Give a positive score

Re: How can I change strings value?

Postby schnellboot » Sat Dec 18, 2010 11:17 am

gimme an example
schnellboot
 
Posts: 819
Joined: Sat Mar 31, 2007 1:35 pm
Location: Germany
Score: 102 Give a positive score

Re: How can I change strings value?

Postby tzoli » Sat Dec 18, 2010 11:29 am

I have a string.It's empty and I want to change this value.
Creepers are capable of climbing ladders, despite lacking arms. (Minecraft wiki)
User avatar
tzoli
 
Posts: 343
Joined: Sat Jun 12, 2010 6:54 pm
Location: Behind you
Score: 15 Give a positive score

Re: How can I change strings value?

Postby skydereign » Sat Dec 18, 2010 8:10 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: How can I change strings value?

Postby tzoli » Sat Dec 18, 2010 8:11 pm

Thank you :)
Creepers are capable of climbing ladders, despite lacking arms. (Minecraft wiki)
User avatar
tzoli
 
Posts: 343
Joined: Sat Jun 12, 2010 6:54 pm
Location: Behind you
Score: 15 Give a positive score

Re: How can I change strings value?

Postby tzoli » Sun Dec 19, 2010 6:46 am

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;
Creepers are capable of climbing ladders, despite lacking arms. (Minecraft wiki)
User avatar
tzoli
 
Posts: 343
Joined: Sat Jun 12, 2010 6:54 pm
Location: Behind you
Score: 15 Give a positive score

Re: How can I change strings value?

Postby skydereign » Sun Dec 19, 2010 7:11 am

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
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: How can I change strings value?

Postby tzoli » Sun Dec 19, 2010 9:49 am

No-No...The file1 is name of string
Creepers are capable of climbing ladders, despite lacking arms. (Minecraft wiki)
User avatar
tzoli
 
Posts: 343
Joined: Sat Jun 12, 2010 6:54 pm
Location: Behind you
Score: 15 Give a positive score

Re: How can I change strings value?

Postby skydereign » Sun Dec 19, 2010 10:08 am

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);
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest