PDA

View Full Version : [SOLVED] String read from a file isn't the one in the file???



crazyfuturamanoob
November 22nd, 2008, 07:31 PM
I use C.

This string:

data/test.bmp
Will look like this:

�?޷�<Ϸ�?޷����=�.e#

With this code:


int line_max = 80;
char line[line_max];

char string[line_max];
strcpy( string, line );

// remove the endline character from string
string[strlen(string)-1] = '\0';

printf("%s\n", string);


Am I using wrong data types? How is this possible?

Edit: Solved myself.
When creating a string variable, it will be filled with garbage.
And I forgot to read the line from file before doing that part of code, lol.

nvteighen
November 22nd, 2008, 10:14 PM
Which leads us to the old saying: "Always initialize your memory".