i m doing a program now. in which i need to get ascii values like SOH, NUL etc from the serial port.
i m getting the values as string. i don know how to process the ascii values to obtain the original values back.

example my data is
SOH NUL = 0x01 0x00

6 Years
Discussion Span
Last Post by sridhar.selva

Too vague to answer. What does "obtain the original values back" mean? You have a string and you can't extract the ASCII values? You can't display non-printable characters? The string is corrupted? You're not reading correctly from the serial cable? Etc.?


You can't be getting you data as a string since NUL cannot be part of a string. SOH is questionable too.

You are getting your data ins a character array.


hey thanks,
actually i need to print the ascii values instead of the characters,
i mean that i ll be getting the ascii values and i need to print the ascii values,

if i get "SOH STX NUL 0",
i have to print "01320232003248" likewise, i tried with this code

int i=0;
char str[32];
for(i=0; i<strlen(str); i++)
printf("%c   %d", str[i], str[i]);

by this i could print it succesfully, but i wanna know is there any way to store it another variable array???


gets, strlen. printf with a "%c" argument. These are all for strings and printable characters. You need to use low-level read and write commands, not functions like "gets". If NULL means anything but a NULL terminator, you can't think of this in terms of strings. Rename your character array. It can only confuse things to call it "str". It's not a string.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.