collinm <> wrote:
> Walter Roberson wrote:
>>
>> : char msg[]="\\000\\000\\000\\000\\000\\001Z00\\002AA LINUX
> \\004";
>>
>> That doesn't correspond to what you are doing in bash. The
> correspondance
>> would be
>>
>> char msg[] = {'\0', '\0', '\0', '\0', '0', '0', '\1', '0', '0',
>> '\2', 'A', 'A', ' ', 'L', 'I', 'N', 'U', 'X', '\4'
> };
>>
>> a) in your bash version you have a \000 in one place instead of a
> \\000
> why some characters have \ in front of them and some not?
Because '\0' and '0' are two different characters. The first one ('\0')
is the character with the numerical value 0, while the second is the
character that will be printed as the character 0 but will have the
numerical value 48 if your machines uses the ASCII character encoding.
Same for the difference between '\1' and '1' etc. Or do you mean the
difference in bash? That's a question for comp.unix.shell or maybe
comp.unix.programmer since it's nothing related to C.
> where is the Z?
Walter forgot it, just put it in where it's missing (i.e. after the
'\1' character).
> they surely miss a '\0', because in the msg array, there a 5 null
Then put it in. The corrected version would be
char msg[ ] = { '\0', '\0', '\0', '\0', '\0', '\1', 'Z', '0', '0',
'\2', 'A', 'A', ' ', 'L', 'I', 'N', 'U', 'X', '\4' };
>> b) in your bash version the characters after the Z are literal, not
>> numeric;
>
> ya i know, in bash i can mix octal characters with literal...
> i need to do the same thing with the C program
What is "the same thing"? Octal, decimal, hexadecimal or whatever
way a value is represented in the program is irrelevant.
>> c) using char[] with an initialized string is going to result in a
> trailing
>> '\0' being put on that is not present in your original. As you are
> already
>> dealing with null characters, this could be significant.
> what i need to do to resolve that?
Take care that you don't use functions that expect strings (i.e. char
arrays that are terminated by a '\0' character) with that array and
to pass the correct length of the array to functions that operate on
simple arrays. You can determine the length by using e.g. 'sizeof msg'.
Regards, Jens
--
\ Jens Thoms Toerring ___
\__________________________
http://www.toerring.de