Hi coder,
CC> The following pseudo-code has an unfortunate side effect:
CC> (using Borland c++ 4.51)
CC> ofstream outf("out.bin");
CC> char string[6];
CC> strcpy(string,"12345");
CC> string[strlen(string)] = '\n';
CC> outf.write(string, strlen(string));
CC> outf.close();
CC> The side effect is that it writes the following:
CC> 12345#13#10 (where #13 & #10 are ascii characters)
CC> What the hell am I doing wrong?
"12345" won't mean that U will have |1|2|3|4|5| in memory, but that U will
have |1|2|3|4|5|#0| ( when #0 means end of string )
Then, if U make only a printf with string after put a |#13|#10|,
he will write :
12345
dfhdfh#^!‡{djghjŠ(^^^!‡Š{^#@@!(‡'—æ$
... and so on ... until he found a #0
--Hoping it would be useful 2 U--
Ciao
FeP
... Coding is so funny...
--- Blue Wave/DOS v2.30
---------------
* Origin: Programmer's Paradise -Belgium- 32-10-813088 (2:293/2009)
|