473,320 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Can't match char 0x10.

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[i]==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];
++i;
}
++alerts.len;
}
Nov 14 '05 #1
3 2569
On Sat, 21 May 2005 03:00:54 GMT, "jt" <jt****@hotmail.com> wrote in
comp.lang.c:
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[i]==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];
++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.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #2
On Sat, 21 May 2005 03:00:54 GMT, "jt" <jt****@hotmail.com> wrote:
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[i]==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];
++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[i] == DLE)
{
alerts.msg[alerts.len] = alertmsg[i + 1] - 0x20;
i += 2;
}
else
{
alerts.msg[alerts.len] = alertsmsg[i];
++ 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.

Nov 14 '05 #3
jt
Thanks!

"Paul Mesken" <us*****@euronet.nl> wrote in message
news:ge********************************@4ax.com...
On Sat, 21 May 2005 03:00:54 GMT, "jt" <jt****@hotmail.com> wrote:
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[i]==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];
++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[i] == DLE)
{
alerts.msg[alerts.len] = alertmsg[i + 1] - 0x20;
i += 2;
}
else
{
alerts.msg[alerts.len] = alertsmsg[i];
++ 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.

Nov 14 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: George Hester | last post by:
http://hesterloli.dnsalias.com/test/javascript_image.htm The image is the 100x100 px block. If we right-click in it and try to save the image we cannot. Is it possible to say set a mime-type so...
7
by: alphatan | last post by:
Is there relative source or document for this purpose? I've searched the index of "Mastering Regular Expression", but cannot get the useful information for C. Thanks in advanced. -- Learning...
2
by: Tom | last post by:
I'm getting this error when I try to pass a structure to a dll. An unhandled exception of type 'System.ArgumentException' occured in Test1.exe Additional Information: Type could not be marshaled...
77
by: Aman JIANG | last post by:
THE GAME : Write a C function to swap the bits of a char so that its bits would become the mirror image of the char.MSBs become its LSBs etc. E.g. 11001100 binary would become 00110011 binary....
2
by: jmprince01 | last post by:
in C, write a function which will find the first occurance of the string s in the string str and will return a pointer to the first match if such a match occurs. if there is no match, then...
4
by: ranjanmg1 | last post by:
I have a unsigned char.. i need to reverse it.. what the easiest way to do it?? i dont want to tap each bit save and restore etc etc.... Is it possible to perform some bitwise operation which...
10
by: somebody | last post by:
There are two files below named search.c and search.h. In the for loop in search.c, the for loop never exits, even if mystruct.field1 has no match. Instead of exiting the for loop it keeps going...
3
by: jacob600 | last post by:
Hello, I am very new to Perl. I have been trying to modify an existing script that is used to read tcpdump files and then eventually generate Top Talker stats from it. If my tcpdump file from...
1
by: Peng Yu | last post by:
Hi, '\b' only match the boundary between alphanumerical char and nonalphanumerical char. I'm wonder if there is a generic metacharacter to match the boundary between any non intersected char set...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.