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

Char** == "something" help

Hi all,

I have the following problem:
I have to revise a c++ dll. And i'm new to c++.
I have to change a function, but i cannot change it's structure.
I want to check the parameters and act according to those parameters.
I've tried several ways to resolve it, but without success.
Could anybody help? Thanks in advance.

Rob Smeets
SomeFunction(const char** pParameters)
{
int i;
bool NTLOGIN;
for (i = 0;pParameters[i] != (char*) 0 && pParameters[i+1] != (char*) 0;i += 2)
{
char* key = pParameters[i];
char* value = pParameters[i+1];
if key == "ntlogin" // this comparison is never true
{ if value == "TRUE" // this comparison is never true
{
NTLOGIN = TRUE; // this bool is never True
}
}
}
}
Jul 22 '05 #1
4 2026

"Rob Smeets" <p.********@schretlen.com> wrote in message
news:c4**************************@posting.google.c om...
Hi all,

I have the following problem:
I have to revise a c++ dll. And i'm new to c++.
I have to change a function, but i cannot change it's structure.
I want to check the parameters and act according to those parameters.
I've tried several ways to resolve it, but without success.
Could anybody help? Thanks in advance.

Rob Smeets
SomeFunction(const char** pParameters)
{
int i;
bool NTLOGIN;
for (i = 0;pParameters[i] != (char*) 0 && pParameters[i+1] != (char*) 0;i += 2) {
char* key = pParameters[i];
char* value = pParameters[i+1];
if key == "ntlogin" // this comparison is never true
{ if value == "TRUE" // this comparison is never true
{
NTLOGIN = TRUE; // this bool is never True
}
}
}
}


Use strcmp to compare strings, not ==

#include <string.h>

if (strcmp(key, "ntlogin") == 0)

Suggest you buy a book on C++. It has lots and lots of gotchas to catch the
unwary programmer trying to learn C++ on the hoof, as you seem to be. You
just found the first.

john
Jul 22 '05 #2
Rob Smeets wrote:
SomeFunction(const char** pParameters)
{
int i;
bool NTLOGIN;
for (i = 0;pParameters[i] != (char*) 0 && pParameters[i+1] != (char*) 0;i += 2)
{
char* key = pParameters[i];
char* value = pParameters[i+1];
if key == "ntlogin" // this comparison is never true
{ if value == "TRUE" // this comparison is never true
{
NTLOGIN = TRUE; // this bool is never True
}
}
}
}


Your code doesn't even compile. Use std::string instead of char* and
many of your problems will be solved. ( You can't compare char* using
==, but you can compare std::string using == )

string key = pParameters[i];
string value = pParameters[i+1];

And put some () around the if-conditions

if( key == "ntlogin" )

if( value == "TRUE" )

And use true, instead of TRUE for bool variable

NTLOGIN = true;
Jul 22 '05 #3
"John Harrison" <jo*************@hotmail.com> typa:

"Rob Smeets" <p.********@schretlen.com> wrote in message
news:c4**************************@posting.google. com...
Hi all,

I have the following problem:
I have to revise a c++ dll. And i'm new to c++.
I have to change a function, but i cannot change it's structure.
I want to check the parameters and act according to those parameters.
I've tried several ways to resolve it, but without success.
Could anybody help? Thanks in advance.

Rob Smeets
SomeFunction(const char** pParameters)
{
int i;
bool NTLOGIN;
for (i = 0;pParameters[i] != (char*) 0 && pParameters[i+1] != (char*) 0;i

+= 2)
{
char* key = pParameters[i];
char* value = pParameters[i+1];
if key == "ntlogin" // this comparison is never true
{ if value == "TRUE" // this comparison is never true
{
NTLOGIN = TRUE; // this bool is never True
}
}
}
}


Use strcmp to compare strings, not ==

#include <string.h>

if (strcmp(key, "ntlogin") == 0)

Suggest you buy a book on C++.

One book that don't assume you know C language ;-)
--
Pierre
Jul 22 '05 #4
Aggro wrote:
Your code doesn't even compile. Use std::string instead of char* and
many of your problems will be solved. ( You can't compare char* using
==, but you can compare std::string using == )


Oh, you can compare them, it's just that the comparison won't do what
the OP thinks it will. Or it might, in certain situations.

Brian Rodenborn
Jul 22 '05 #5

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

Similar topics

14
by: juglesh | last post by:
"$string = isset($xyz) ? $xyz : "something else";" Hello, someone gave code like this in another thread. I understand (by inference) what it does, but have not found any documentation on...
8
by: Sam Sungshik Kong | last post by:
Hello! I use Python for ASP programming. I found something weird. Response.Write(Request("something")) It draws "None" when there's no value for something. Actually I expect "" instead of...
2
by: Helen | last post by:
I've written a web control that allows you to hide certain bits of your page when the specified selectbox has a certain value. It's a simple enough bit of logic, but I got sick of coding it again...
44
by: Tolga | last post by:
As far as I know, Perl is known as "there are many ways to do something" and Python is known as "there is only one way". Could you please explain this? How is this possible and is it *really* a...
5
by: tuxedo | last post by:
The way the <body onload="something()"works ensures that the complete html document is loaded before something() is executed. Can the same be achieved when placing the onload call in document...
4
by: marcwentink | last post by:
This probably is a very noob question What is the return type of Session("Something")? I want to change: If Not Session("Name") Is Nothing Then LoginId = Session("Name").ToString to...
5
by: magix8 | last post by:
Hi, I have form GET method, example: index.asp?Type=1&Type=3&Type=4&.... So, I have something like this at the receiver side to retrieve multiple Type value and insert into tables.
7
by: Brice Rebsamen | last post by:
Reading the code from showkey.c (from package kbd) I found this type of code: char *m; m = "RAW"; See below for the complete code. How can this work? I would have used strdup, or allocation...
2
by: =?ISO-8859-1?Q?Pekka_J=E4rvinen?= | last post by:
Hi, How I can find <?something ?stuff? XML: <Wix> <?define UpgradeCode="{foobar-quux-xyzzy}"?> <?define Manufacturer="Company"?> <!-- update this ALWAYS --> <?define PackageCode="REPLACE"?>
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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: 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
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.