![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Korn: How to loop through a string character by character | shew01 | Shell Programming and Scripting | 10 | 12-02-2008 07:58 AM |
| Converting integer to String | ROOZ | Shell Programming and Scripting | 1 | 06-05-2008 01:38 PM |
| Converting the case of the string? | skyineyes | Shell Programming and Scripting | 5 | 07-09-2007 05:27 AM |
| command for converting string to integer | esham | Shell Programming and Scripting | 1 | 08-04-2005 07:20 AM |
| converting string to unicode | webtekie | Shell Programming and Scripting | 1 | 07-21-2004 11:43 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
converting character string to hex string
HI
Hi I have a character string which contains some special characters and I need it to display as a hex string. For example, the sample i/p string: ×¥ïA Å gïÛý and the o/p should be : D7A5EF4100C5010067EFDBFD Any pointers or sample code pls. |
|
||||
|
That will not work. It will print the pointer to the string as hex, not the string itself.
How about this: Code:
{
const char *str="asdf";
int n;
for(n=0; str[n] != '\0'; n++)
printf("%02x",(unsigned char)str[n]);
}
[edit] Nope, that doesn't work. Your string contains a NULL. Either that or it's unicode... working on it... Last edited by Corona688; 09-20-2006 at 01:09 PM.. |
|
||||
|
Thanks corona, It works fine.
I have one more doubt regarding sizeof(string). For ex:- If I have code, char func(char funcstr[12]){ printf("%d\n",sizeof(funcstr)); } main() { char mainstr[12]; func(mainstr); printf("%d\n",sizeof(mainstr)); } size of mainstr is giving the array size(i.e. 12), whereas funcstr is giving the pointer size(i.e. 4), will it not give the array size as we declared it as array ? Thanks |
|
||||
|
Your string is 16-bit unicode. How are you reading it??
Once you've inputted a 16-bit unicode string, you can print it like this: Code:
#include <stdio.h>
#include <string.h>
int main()
{
int n;
unsigned short int ustr[]=
{ 0xD7A5, 0xEF41, 0x00C5, 0x0100, 0x67EF, 0xDBFD, 0x0000};
for(n=0; ustr[n] != 0x0000; n++)
printf("%04x",ustr[n]);
printf("\n");
return(0);
}
![]() |
|
||||
|
CODE TAGS FOR CODE PLEASE.
Anyway. It is giving the array size for the array because it is an array. It is giving the pointer size for the passed array because it is a pointer -- arrays are passed by reference. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|