Re: strange problem
- From: Guy Harris <gharris flashcom net>
- To: Eamonn Martin Galvin <galvin student cs ucc ie>
- Cc: gtk-list gnome org
- Subject: Re: strange problem
- Date: Mon, 26 Mar 2001 20:15:49 -0800
On Mon, Mar 26, 2001 at 08:05:55PM +0100, Eamonn Martin Galvin wrote:
> > I have code that looks like this:
> >
> > char tmp[2] = {0};
Then you'd better not put a string into "tmp" that has more than *ONE*
character in it, as a 2-element array of "char" has room for a
1-character string - 1 character, plus the terminating '\0'.
> > char *tok[256]; //this contains 256 2 character strings
2-character strings as in "XY", or 2-byte strings as in "X" (1 byte of
'X', one byte of '\0')?
if it's the former, you'd better do
char tmp[3];
instead (there's no need to initialize it to 0). If you try to copy a
2-character string to a 2-element array of "char", all sorts of random
things can happen.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]