Using \x I can specify hexadecimal numbers in strings in C, but if I put \x00 then it interprets it as an instruction to terminate the string. As a result I can't express a hexadecimal number with 00 in it using a string! Is there some way around this?

No way around it if you want to use normal string handling functions found in string.h and stdio.h. You will have to treat the character array as containing binary data.

Well, I suppose you could create the string to contain normal decimal values such as char num[] = "01";

Using \x I can specify hexadecimal numbers in strings in C, but if I put \x00 then it interprets it as an instruction to terminate the string. As a result I can't express a hexadecimal number with 00 in it using a string! Is there some way around this?

no u cant do that. But if u want to contain that in a string u can try by declaring a
char *str;
variavle and store whatever u want, say
*(str+4) = 0;
and then u can proceed with *(str+5)='a' etc. But if u do this u wont be able to apply any inbuilt functions available in string.h since it will take the 0 as string termination mark. U have to write ur own functions to achieve whatever u want. the only thing extra u will need to do is to keep a length variable along with that or if u use c++ u can write your own string class such that

class MyString
{
char *str;
int length;
public:
MyString();
int length();
....
...//etc....
}

There are a few win32 api functions that use embedded '\0', what they do is use two of them to indicate the end of the data. But there again they had to write their own function to parse the character array.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.