about convertions


 
Thread Tools Search this Thread
Top Forums Programming about convertions
# 1  
Old 11-17-2006
about convertions

hi
i got in this way

DIR *dd;
dd = opendir("/root/ramesh/");
.....
then now i have problem
how can i convert a string to hexadecimals
ex: ram/es:h

show me the way

thank you for your feedback

ramesh
# 2  
Old 11-17-2006
printf("%x", <character>) converts individual characters
Code:
char *a="ram/es:h"
char *p=a;
for( ; *p; p++)
    printf("%2x", (int)*p);
printf("\n");

# 3  
Old 11-17-2006
convertions

thank you jim
it is great.
your is working fine
but in that i would like to convert only symbols.
not text.
sorry for trouble you.
Ex:
char *name="rames:h/"
i want to store it as "rames3ah2f"
can you show me the way

thank you for your feedback

ramesh
# 4  
Old 11-17-2006
If I take your meaning correctly:
Code:
{
  char buf[512];
  sprintf(buf,"%s%x","rames",0x3ah2f);
}

# 5  
Old 11-17-2006
I think he wants punctuation converted to hex:
Code:
#include <ctype.h>
int main()
{
	char *a="rames:h/";
	char *p=a;
	for (; *p; p++)
		printf(ispunct(*p)?"%2x":"%c",(int)*p);
	printf("\n");
	return 0;
}

Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question