function to save string to file

Posted By: Toon

function to save string to file - 06/20/08 15:02

I've written a function to save a certain string to a file but it says that when it tries to write the string the string is an invalid pointer

here is the code i use

Code:
string temp_save_str1[100];
string temp_save_str2[100];

var_nsave save_handle;

function save_str(string_,dir_,number_)
{
	str_cpy(temp_save_str1,dir_);
	str_cat(temp_save_str1,"\\");
	str_cat(temp_save_str1,"\\");
	
	if(number_ < 10)
	{
		str_cat(temp_save_str1,"0");
	}
	str_for_num(temp_save_str2,number_);
	
	str_cat(temp_save_str1,temp_save_str2);
	
	str_cat(temp_save_str1,".txt");
	
	wait(1);
	str_cpy(temp_save_str2,string_);
	
	sleep(1);
	
	save_handle = file_open_write(temp_save_str1);
	
	file_str_write(save_handle,temp_save_str2);

	//file_close(save_handle);
}

function test()
{
	save_str("save this data in text file","gamedata",1);
}

on_z = test();

Posted By: Helghast

Re: function to save string to file - 06/20/08 15:48

have you checked your output of the string?

it seems you create a string called:

"gamedir\\\\01.txt"

you sure that "\\\\" is correct?

and yes, close the handle again wink

otherwise it looks fine to me...
I'm just not sure if you can access folder from there too, have you tried it without creating the directory string too?

regards,
Posted By: JimFox

Re: function to save string to file - 06/21/08 17:40

Hi,
This is a wild guess, but perhaps the compiler does not like the sequence \". Change your characters being saved to see if that is your problem. Try something like 99 instead of \\ and see if that works.
Blessings.........
Jim
© 2024 lite-C Forums