F
FlorinBr
Hello! I am trying to initialize a lookup table, which consists of
characters. The problem is that I need the characters in hexadecimal.
So, I tried the following:
<code>
#define UNSUPPORTED '\xff'
typedef struct _this_stuff {
char tut[5];
char a;
char mnames[2][6];
} stuff;
static stuff sh[] ={
{ "ura" , 3 , {
{ UNSUPPORTED , '\xa9' , '\xb9' , UNSUPPORTED ,
'\xb9' }
}
},
{ "mimi" , 4 , {
{ UNSUPPORTED , '\xbb' , UNSUPPORTED , UNSUPPORTED ,
'\xcc' }
}
},
{ "" , 5 , {
/*none*/ }
},
};
main() {
printf("%x.\n", sh[0].mnames[0][2]);
}
<\code>
I get the following output: ffffffb9
However, if I use the more frequently-used initializer for chars,
without an escape sequence, I get the right output. that is, when
using the code:
<code>
#define UNSUPPORTED '\xff'
typedef struct _this_stuff {
char tut[5];
char a;
char mnames[2][6];
} stuff;
static stuff sh[] ={
{ "ura" , 3 , {
{'a','l','b','a'},
}
},
{ "mimi" , 4 , {
{'n','e','a','g','r','a'},
}
},
{ "" , 5 , {
/*none*/ }
},
};
main() {
printf("%x.\n", sh[0].mnames[0][2]);
}
<\code>
I get the output:b
Where is it going wrong?
characters. The problem is that I need the characters in hexadecimal.
So, I tried the following:
<code>
#define UNSUPPORTED '\xff'
typedef struct _this_stuff {
char tut[5];
char a;
char mnames[2][6];
} stuff;
static stuff sh[] ={
{ "ura" , 3 , {
{ UNSUPPORTED , '\xa9' , '\xb9' , UNSUPPORTED ,
'\xb9' }
}
},
{ "mimi" , 4 , {
{ UNSUPPORTED , '\xbb' , UNSUPPORTED , UNSUPPORTED ,
'\xcc' }
}
},
{ "" , 5 , {
/*none*/ }
},
};
main() {
printf("%x.\n", sh[0].mnames[0][2]);
}
<\code>
I get the following output: ffffffb9
However, if I use the more frequently-used initializer for chars,
without an escape sequence, I get the right output. that is, when
using the code:
<code>
#define UNSUPPORTED '\xff'
typedef struct _this_stuff {
char tut[5];
char a;
char mnames[2][6];
} stuff;
static stuff sh[] ={
{ "ura" , 3 , {
{'a','l','b','a'},
}
},
{ "mimi" , 4 , {
{'n','e','a','g','r','a'},
}
},
{ "" , 5 , {
/*none*/ }
},
};
main() {
printf("%x.\n", sh[0].mnames[0][2]);
}
<\code>
I get the output:b
Where is it going wrong?