Hi, all,

I'm converting assembly src to C,

as u see below, my problem is just it...

help me....^^;



;; in asm
.data

BinaryAsciiZ db "abc01.txt", 0
....
;some code
mov BinaryAsciiZ[4], '0'; // it's ok!!!


;; in C

char *BinaryAsciiZ = "abc01.txt";
;; code...
mov BinaryAsciiZ[4] = '0'; // => access error!!!

Posted on 2003-01-10 16:57:16 by muzidowa
a char* variable is a variable that holds a pointer. When you say...

char *BinaryAsciiZ = "abc01.txt";

your tellin c++ "Make a constant string containing the text 'abc01.txt' and make the variable BinaryAsciiZ point to that constant string."

Think about it... if you type a string directly into your source code, you dont want some bad code to start changing it on you. Of course you can freely change BinaryAsciiZ to any value you want, but you cannot change the data it points to because its constant data.

The solution is to make a character array instead of a pointer.....

char BinaryAsciiZ[] = "abc01.txt";

This is tellin c++ "Make an array of character variables and copy the characters 'abc01.txt' to that array." Since you defined BinaryAsciiZ is a variable, u are free to change the data that it contains.
Posted on 2003-01-10 17:34:54 by BubbaFate
Thanks, BubbaFate!!

Have a nice day~
Posted on 2003-01-10 18:24:20 by muzidowa