Cant write into files

Posted By: Tempelbauer

Cant write into files - 08/15/10 21:34

hi
maybe i get stupid, but i cant write a string in a file. this is my code:
Code:
int foo(STRING* file)
{	
	int f = file_open_write(file);
	if(f!=0)
	{
		STRING* out = "test";
		file_str_write(f,out);
		file_close(f);
	}
	
}



i call this function in main using
Code:
foo("E:\\Dokumente\\out.txt");



i get "Crash in foo: SYS" (Error E1513)
the exception is thrown by the file_str_write-function (i´ve debugged it)

the file is created on disk
the directory is a normal dir. other programs can write files in it without restrictions


where is the problem?? this is driving me insane...
Posted By: WretchedSid

Re: Cant write into files - 08/15/10 21:38

Code:
STRING* out = "test";



This is not an initialized string object. It's a STRING pointer pointing to a CString. What you need is str_create or just pass a pointer to a STRING object to the function.
Posted By: Aku_Aku

Re: Cant write into files - 08/15/10 21:39

Perhaps not int but var.
var f = file_open_write(file);
In the manual:
file_str_write (var handle, STRING* string)
Posted By: Lukas

Re: Cant write into files - 08/15/10 21:39

STRING* out = "test";

This is wrong and I think in the most recent A7/A8 version this should return a sytax error. Define your string outside a function, or like this:

STRING* out = str_create("test");

EDIT: Damn, two people were faster than me. The var thing could also be an issue, because the var that is returned gets an implicit int cast.
Posted By: Tempelbauer

Re: Cant write into files - 08/15/10 21:40

now:
Code:
int foo(STRING* file)
{	
	var f = file_open_write(file);
	if(f!=0)
	{
		STRING* out = str_create("test");
		file_str_write(f,out);
		file_close(f);
	}
	
}



edit: aku is right. the problem is the int var

thanks fpr the help
© 2024 lite-C Forums