Can't match char 0x10.

J

jt

Ref: I'm building a new character array (alerts.msg).

I have a character array with a mix of binary and text characters with is
"alertmsg". Some of the characters are a DLE (0x10) char that I need to
trigger off of and then subtract the next char by 0x20. I'm not able to
match the DLE as I go thru the character array.

Also, I'm I substracting the character correctly.

Below is a snippet of my code. Can you see if I am doing something wrong?
Thanks!

===================== code snippet ======================
#define DLE 0x10

alerts.len=0;
tlen=strlen(alertmsg);

for (i=0; i<=tlen;i++)
{
if (alertmsg==DLE) -----> can't find a match as I go thru the
character array.
{
alerts.msg[alerts.len]= alertmsg[i+1] - 0x20;
i+=2;
}else{
alerts.msg[alerts.len]=alertmsg;
++i;
}
++alerts.len;
}
 
J

Jack Klein

Ref: I'm building a new character array (alerts.msg).

I have a character array with a mix of binary and text characters with is
"alertmsg". Some of the characters are a DLE (0x10) char that I need to
trigger off of and then subtract the next char by 0x20. I'm not able to
match the DLE as I go thru the character array.

Also, I'm I substracting the character correctly.

Below is a snippet of my code. Can you see if I am doing something wrong?
Thanks!

===================== code snippet ======================
#define DLE 0x10

alerts.len=0;
tlen=strlen(alertmsg);

for (i=0; i<=tlen;i++)
{
if (alertmsg==DLE) -----> can't find a match as I go thru the
character array.
{
alerts.msg[alerts.len]= alertmsg[i+1] - 0x20;
i+=2;
}else{
alerts.msg[alerts.len]=alertmsg;
++i;
}
++alerts.len;
}


What mix of binary and text characters? If there is a character with
a value of binary 0 in the array, strlen will return the number of
characters up to and excluding that byte. So if there is a 0x00,
'\0', or just plain 0 in the array before the 0x10 character, your
loop will end before you get to it.

If that is not it, you need to show the definition of the alerts
structure, the alertmsg array, and the code that puts data into the
alertmsg array.
 
P

Paul Mesken

Below is a snippet of my code. Can you see if I am doing something wrong?
Thanks!

===================== code snippet ======================
#define DLE 0x10

alerts.len=0;
tlen=strlen(alertmsg);

for (i=0; i<=tlen;i++)
{
if (alertmsg==DLE) -----> can't find a match as I go thru the
character array.
{
alerts.msg[alerts.len]= alertmsg[i+1] - 0x20;
i+=2;
}else{
alerts.msg[alerts.len]=alertmsg;
++i;
}
++alerts.len;
}


Is your code supposed to go through the array with a stride of 2
instead of 1? It doesn't check the elements with an odd index until it
encounters the value DLE.

Here's how the "while" version looks like of the "for" block :

i = 0;
while(i <= tlen)
{
if (alertmsg == DLE)
{
alerts.msg[alerts.len] = alertmsg[i + 1] - 0x20;
i += 2;
}
else
{
alerts.msg[alerts.len] = alertsmsg;
++ i; // First increment of i in loop
}
++ alerts.len;
++ i; // Second increment of i in loop
}

As long as no DLE value is encountered in your array, only the
elements with an even index will be checked because i is increased
twice, once explicitly in the "else" block, the second time implicitly
by the "for" statement (made here explicitly in the "while" loop).

If a DLE value is encountered then i is increased by 3.
 
J

jt

Thanks!

Paul Mesken said:
Below is a snippet of my code. Can you see if I am doing something wrong?
Thanks!

===================== code snippet ======================
#define DLE 0x10

alerts.len=0;
tlen=strlen(alertmsg);

for (i=0; i<=tlen;i++)
{
if (alertmsg==DLE) -----> can't find a match as I go thru the
character array.
{
alerts.msg[alerts.len]= alertmsg[i+1] - 0x20;
i+=2;
}else{
alerts.msg[alerts.len]=alertmsg;
++i;
}
++alerts.len;
}


Is your code supposed to go through the array with a stride of 2
instead of 1? It doesn't check the elements with an odd index until it
encounters the value DLE.

Here's how the "while" version looks like of the "for" block :

i = 0;
while(i <= tlen)
{
if (alertmsg == DLE)
{
alerts.msg[alerts.len] = alertmsg[i + 1] - 0x20;
i += 2;
}
else
{
alerts.msg[alerts.len] = alertsmsg;
++ i; // First increment of i in loop
}
++ alerts.len;
++ i; // Second increment of i in loop
}

As long as no DLE value is encountered in your array, only the
elements with an even index will be checked because i is increased
twice, once explicitly in the "else" block, the second time implicitly
by the "for" statement (made here explicitly in the "while" loop).

If a DLE value is encountered then i is increased by 3.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top