hi,
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

Recommended Answers

All 5 Replies

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,

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

main()
{
int i=0;
char str[32];
gets(str);
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.

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.