Re: [Lug-Nuts] C problems

From: Linux Rocks (gnulinux@rosecomputing.com)
Date: Sun Oct 24 1999 - 18:42:28 PDT


On Thu, Oct 21, 1999 at 05:44:12PM -0700, Brian Lavender wrote:
> I am trying to get this simple C program to work and no go. What
> am I doing wrong?

> char salt[2];
>
> strcpy(salt,"ab");

In the code above you declare a variable of type 'char' that is two
bytes in size (assuming 1 char = 1 byte). Later in the code you use
'strcpy' (I like to think if this function as string copy) to copy the
string "ab" into the variable 'salt'. However, the variable 'salt'
contains only two bytes and you really need three bytes to properly
store the string "ab". You need a byte to store "a", a byte to store "
b", and lastly you need a byte to store the string terminator (usually
0). As a result if you try to use salt as a string your results will
likely be undefined.



This archive was generated by hypermail 2b29 : Fri Feb 25 2000 - 14:29:07 PST