473,387 Members | 1,290 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,387 software developers and data experts.

How to compare these variables by use operator 'AND'

Dear all,

I have a problem about compare the 2 variables by use operator
'AND' while one variable is the int constant 0x00000002 and the other
one is string '0x202'

for the constant 0x00000002 is the flag of systemcall OPEN following
fcntl.h

#define O_RDWR 0x00000002 /* open for reading and
writing */

and the string '0x202' is the variable which I got from use command
strtok cut string from output of ktruss such as I got
bufft value-->open("testprg.txt", 0x202, 0x8049bb0)

The below is my code whic use to cut string buff
char test[80], **strsysc=NULL;
char *sep = "()\",";
char *word, *brkt;
int i=0;
int aa;

strsysc=(char**)calloc(4,sizeof(char*));
printf("bufft value -->%s\n",buff);
strcpy(test,buff);
printf("test value %s\n",test);
for (word = strtok_r(test, sep, &brkt);
word;
word = strtok_r(NULL, sep, &brkt))
{
strsysc[i]=word;
printf("word==>%s\n",strsysc[i]);
i=i+1;
}

from code I got strsysc[2] = '0x202'
and I'd like to use 'AND' to compare it

like this if(0x00000002 & strsysc[2])
I cannot use because strsysc[2] is string and I try to use
atoi[strsysc[2]] the runtime error said Memory fault.

Please give me suggestion about this case

Regards,
Pattanawadee
Nov 13 '05 #1
5 2223
pattanawadee wrote:
Dear all,

I have a problem about compare the 2 variables by use operator
'AND' while one variable is the int constant 0x00000002 and the other
one is string '0x202'

for the constant 0x00000002 is the flag of systemcall OPEN following
fcntl.h

#define O_RDWR 0x00000002 /* open for reading and
writing */

and the string '0x202' is the variable which I got from use command
strtok cut string from output of ktruss such as I got
bufft value-->open("testprg.txt", 0x202, 0x8049bb0)

The below is my code whic use to cut string buff
char test[80], **strsysc=NULL;
char *sep = "()\",";
char *word, *brkt;
int i=0;
int aa;

strsysc=(char**)calloc(4,sizeof(char*));
printf("bufft value -->%s\n",buff);
strcpy(test,buff);
printf("test value %s\n",test);
for (word = strtok_r(test, sep, &brkt);
word;
word = strtok_r(NULL, sep, &brkt))
{
strsysc[i]=word;
printf("word==>%s\n",strsysc[i]);
i=i+1;
}

from code I got strsysc[2] = '0x202'
and I'd like to use 'AND' to compare it

like this if(0x00000002 & strsysc[2])
I cannot use because strsysc[2] is string and I try to use
atoi[strsysc[2]] the runtime error said Memory fault.

Please give me suggestion about this case

Use `strtol' instead. It will deal with numbers rendered in hex
properly.

HTH,
--ag


--
Artie Gold -- Austin, Texas

Nov 13 '05 #2
On 21 Sep 2003 21:41:23 -0700, sp******@unicorn.eng.psu.ac.th
(pattanawadee) wrote:
Dear all,

I have a problem about compare the 2 variables by use operator
'AND' while one variable is the int constant 0x00000002 and the other
one is string '0x202'
There is no AND operator in C. There are, however, two operators
which have the word "and" in their titles. It is a shame you don't
tell us which one you mean until some 40 lines later.

for the constant 0x00000002 is the flag of systemcall OPEN following
fcntl.h

#define O_RDWR 0x00000002 /* open for reading and
writing */

and the string '0x202' is the variable which I got from use command
strtok cut string from output of ktruss such as I got
bufft value-->open("testprg.txt", 0x202, 0x8049bb0)

The below is my code whic use to cut string buff
char test[80], **strsysc=NULL;
char *sep = "()\",";
char *word, *brkt;
int i=0;
int aa;

strsysc=(char**)calloc(4,sizeof(char*));
You did not include stdlib.h which causes the call to calloc to invoke
undefined behavior. If you hadn't included the unnecessary and
undesirable cast, the compiler would have issued a diagnostic warning
you about this.
printf("bufft value -->%s\n",buff);
Give us a clue, what is buff?
strcpy(test,buff);
printf("test value %s\n",test);
for (word = strtok_r(test, sep, &brkt);
Where is the prototype for strtok_r? What is its return type. word;
word = strtok_r(NULL, sep, &brkt))
{
strsysc[i]=word;
printf("word==>%s\n",strsysc[i]);
i=i+1;
}

from code I got strsysc[2] = '0x202'
Did you mean "0x202"? If the string actually starts with 0x, atoi
will always return a 0 value since x is not a decimal digit.
and I'd like to use 'AND' to compare it

like this if(0x00000002 & strsysc[2])
& is the bit-wise and operator. It will not tell you if the two
values are equal. It will only tell you if their binary
representations have at least one bit in common on or not.
I cannot use because strsysc[2] is string and I try to use
atoi[strsysc[2]] the runtime error said Memory fault.
Did you mean atoi(strsysc[2])? The statement
if (0x00000002 & (int)strtol(strsysc[2], NULL, 16))
should test the bits of the value represented by strsysc[2].
Please give me suggestion about this case

Regards,
Pattanawadee


<<Remove the del for email>>
Nov 13 '05 #3
Barry Schwarz <sc******@deloz.net> wrote in message news:<bk**********@216.39.135.208>...
On 21 Sep 2003 21:41:23 -0700, sp******@unicorn.eng.psu.ac.th
(pattanawadee) wrote:

You did not include stdlib.h which causes the call to calloc to invoke
undefined behavior. If you hadn't included the unnecessary and
undesirable cast, the compiler would have issued a diagnostic warning
you about this.
sorry !! I cut only some of my code I alredy include stdlib.h.
printf("bufft value -->%s\n",buff);
Give us a clue, what is buff?


bufft value-->open("testprg.txt", 0x202, 0x8049bb0)
if up to what the systemcall is used in this case is case I want to
catch the flag of system call OPEN from buff value it is '0x202'

Did you mean atoi(strsysc[2])? The statement
if (0x00000002 & (int)strtol(strsysc[2], NULL, 16))
should test the bits of the value represented by strsysc[2].


I try test this line follow your suggestion but it still tell me
on runtime error that 'Memory Falut'
What I am doing is I try to modified the ktruss command (file dump.c)
on netbsd
my problem is I cannot find where in dump.c I can get the flag value
of system call OPEN I only can find how to get buff (such as
open("testprg.txt", 0x202, 0x8049bb0) so, I have to cut this for get
the flag value (0x202) and I would like to check if it is the O_RDWR
flag which in fcntl.h define to 0x00000002
so I use & operator.
I test if (0x00000002 & 0x202) it true.
So that means it flag O_RDWR but what I get is string '0x202' so I
cannot..use (0x00000002 & strsysc[2])
I try if (0x00000002 & (int)strtol(strsysc[2], NULL, 16)) it still
tell me runtime error Memory fault


Please give me suggestion about this case

Regards,
Pattanawadee


<<Remove the del for email>>

Nov 13 '05 #4
On 22 Sep 2003 09:11:52 -0700, sp******@unicorn.eng.psu.ac.th
(pattanawadee) wrote:
Did you mean atoi(strsysc[2])? The statement
if (0x00000002 & (int)strtol(strsysc[2], NULL, 16))
should test the bits of the value represented by strsysc[2].


I try test this line follow your suggestion but it still tell me
on runtime error that 'Memory Falut'


You need to provide a reasonably small (less than 500 lines)
compilable example that demonstrates the problem you are having.
<<Remove the del for email>>
Nov 13 '05 #5
Dear Sir,

Now I can solve my problem. It's my fault I don't think that
sometime the value of strsysc[2] is NULL so, it can make error like
that.
Thank you so much for your good suggestion
if (0x00000002 & (int)strtol(strsysc[2], NULL, 16))
that help me so much for my problem

Best Regards,
Pattanawadee

Barry Schwarz <sc******@deloz.net> wrote in message news:<bk**********@216.39.135.80>...
On 22 Sep 2003 09:11:52 -0700, sp******@unicorn.eng.psu.ac.th
(pattanawadee) wrote:
Did you mean atoi(strsysc[2])? The statement
if (0x00000002 & (int)strtol(strsysc[2], NULL, 16))
should test the bits of the value represented by strsysc[2].


I try test this line follow your suggestion but it still tell me
on runtime error that 'Memory Falut'


You need to provide a reasonably small (less than 500 lines)
compilable example that demonstrates the problem you are having.
<<Remove the del for email>>

Nov 13 '05 #6

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

Similar topics

122
by: Einar | last post by:
Hi, I wonder if there is a nice bit twiddling hack to compare a large number of variables? If you first store them in an array, you can do: for (i = 0; i < n; i++) { if (array != value) {...
11
by: Russ Green | last post by:
How does this: public TimeSpan Timeout { get { return timeout; } set { timeout = value; if(timeout < licenseTimeout) licenseTimeout = timeout; }
17
by: Mark A | last post by:
DB2 8.2 for Linux, FP 10 (also performs the same on DB2 8.2 for Windoes, FP 11). Using the SAMPLE database, tables EMP and EMLOYEE. In the followng stored procedure, 2 NULL columns (COMM) are...
10
by: lovecreatesbea... | last post by:
Is it correct and safe to compare a string object with "", a pair of quotation marks quoted empty string?If the string object: s = ""; does s contain a single '\'? Is it better to use...
50
by: titan nyquist | last post by:
I wish to compare two structs via == but it does not compile. I can overload and create my own == but am I missing something that c# already has implemented? ~titan
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.