txt_load/file_str_read - lines with #[number]

Posted By: Anonymous

txt_load/file_str_read - lines with #[number] - 05/04/08 18:08

(A7 7.07.6 / lite-c [maybe c-script])

txt_load and file_str_read can't read lines starting with a '#' followed by a number (the read line is empty).


The script:
 Code:
TEXT*	txt_text = {
	
	strings=10;
	flags=VISIBLE;
	
}

void main(){
	
	video_set(800,600,32,2);
	level_load(NULL);
	
	txt_load(txt_text, "simple.txt");
	
}


with simple.txt like this:

 Code:
1. line
#2. line
3. line
#4. line
5. line
##6. line
7. line
#8. line
9. line
0. line


reads this:

1. line

3. line

5. line
##6. line
7. line

9. line
0. line
Posted By: Spirit

Re: txt_load/file_str_read - lines with #[number] - 05/10/08 15:34

The # and a number at beginning of a string means number of empty spaces.
Posted By: Anonymous

Re: txt_load/file_str_read - lines with #[number] - 05/11/08 08:23

Thats ok for string definitions (STRING* str_mystr = "#255";) but makes no sense reading/writing plain ascii-files. (\n is also not evaluated in ascii-files)
(but thanks for the hint...)
Posted By: jcl

Re: txt_load/file_str_read - lines with #[number] - 05/13/08 11:15

The "#n" syntax also applies for strings in TEXT definitions, including when you preset the strings from a file. It might make no sense in your case, but that's the way it's implemented.
Posted By: Anonymous

Re: txt_load/file_str_read - lines with #[number] - 05/13/08 12:56

Originally Posted By: jcl
The "#n" syntax also applies for strings in TEXT definitions, including when you preset the strings from a file. It might make no sense in your case, but that's the way it's implemented.


then please be consistent and include the cr/lf (\n) in the expected way.
Posted By: jcl

Re: txt_load/file_str_read - lines with #[number] - 05/13/08 13:43

You don't understand. \n is just a convention of the C compiler. The string does not really contain a "\n". Within a string, a new line is the hexadecimal character sequence 0d0a and not "\n".

The "#n" on the other hand is unrelated to the programming language. It is interpreted by the string generator, and thus always causes an empty string no matter if the string is initialized in C code or from a text file.

Hope this helps.

Posted By: zazang

Re: txt_load/file_str_read - lines with #[number] - 05/15/08 02:23

Originally Posted By: jcl
You don't understand. \n is just a convention of the C compiler. The string does not really contain a "\n". Within a string, a new line is the character sequence 0d0a and not "\n".


I have a question on this.

Lets say my string is "start 0d0a end"
Then I write this string into a txt file.
When I open the txt file then will it look like this :-

start
end

thanks
zazang

Posted By: Joey

Re: txt_load/file_str_read - lines with #[number] - 05/15/08 08:49

if your string looks like start \0x0d\0x0a end, yes.
Posted By: Serbanus

Re: txt_load/file_str_read - lines with #[number] - 05/15/08 16:16

Hello guys!

I've been trying the info above but I get not the expected result ... hmmmm

THE GOAL: make a .txt file that looks like this:

start
end

------------------------------------------------------------------

var fHandle; STRING* sSave = " ";
...
function fSave{

fHandle = file_open_write("test.txt");
str_cpy(sSave,"start \0x0d\0x0a end"); file_str_write(fHandle,"sSave"); //1.
str_cpy(sSave,"start 0d0a end"); file_str_write(fHandle,"sSave"); //2.

file_close(fHandle);
}

I get no error but also not the expected result.

Please, someone try it out and explain what am I missing and, if possible, the solution.

:-) THANKS ! :-)
Posted By: Anonymous

Re: txt_load/file_str_read - lines with #[number] - 05/15/08 18:00

Code:
var fHandle; 

...
function fSave{

  fHandle = file_open_write("test.txt");

  file_str_write(fHandle, "start"); //1......
  
  file_asc_write(fHandle, 13);  // cr
  file_asc_write(fHandle, 10);  // lf

  file_str_write(fHandle, "end"); //2......

  file_asc_write(fHandle, 13);  // cr
  file_asc_write(fHandle, 10);  // lf

  file_close(fHandle);
}

Posted By: Serbanus

Re: txt_load/file_str_read - lines with #[number] - 05/15/08 18:15

YEEEEEEEES !

That's the way it works ! This is what I call getting help !
I have enough of "coding in rush" and posting ... just to be there on forum.
Come on guys ... you can better than that, first testing - afterwards posting.

THANK YOU MERCURYUS ! RESPECT ! smile
© 2024 lite-C Forums