473,595 Members | 2,623 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling a const char

I'm struggling with a bit of code that maybe some of you could help me
understand. This code processes character values from streaming data.
I'm trying to get my head around being able to get at the values of a
const char as opposed to a char variable. The code is below:

void GotLevel(const char *szLL, char MM)
{
char ss[1024];
_snprintf(ss, sizeof(ss)
, "%s %c"
, szLL, MM

The characters then get passed to a message window. The problem is when
I try to filter for certain characters. I have no problem doing that
with "char MM"... I can just use:

if(MM == 'B')

However, I can't use the same method for the szLL const char...

if(szLL == 'NYT')

I receive an error message from the compiler: '==' : 'const char *'
differs in levels of indirection from 'int'. How could I go about
filtering for the const char? I'm not understanding something here, so
if anyone sees the error in my logic, please let me know what it might
be. Any help would be very much appreciated.

Best regards,
Marcus

Jul 23 '05 #1
5 1944
Marcus wrote:
I'm struggling with a bit of code that maybe some of you could help me
understand. This code processes character values from streaming data.
I'm trying to get my head around being able to get at the values of a
const char as opposed to a char variable. The code is below:

void GotLevel(const char *szLL, char MM)
{
char ss[1024];
_snprintf(ss, sizeof(ss)
, "%s %c"
, szLL, MM

The characters then get passed to a message window. The problem is when
I try to filter for certain characters. I have no problem doing that
with "char MM"... I can just use:

if(MM == 'B')

However, I can't use the same method for the szLL const char...

if(szLL == 'NYT')

I receive an error message from the compiler: '==' : 'const char *'
differs in levels of indirection from 'int'. How could I go about
filtering for the const char? I'm not understanding something here, so
if anyone sees the error in my logic, please let me know what it might
be. Any help would be very much appreciated.


'const char*' is a pointer to what is usually a sequence of characters
ending on a character that has value 0 (so called 'null character').
Such a sequence is often called "a C string". Comparison of two C
strings is usually done using 'strcmp' function and not the equality
operator:

if (strcmp(szLL, "NYT") == 0) // the 'szLL' points to [a copy of] "NYT"
...

V
Jul 23 '05 #2
On Fri, 15 Apr 2005 13:48:42 -0700, Marcus wrote:
I try to filter for certain characters. I have no problem doing that
with "char MM"... I can just use:

if(MM == 'B')

However, I can't use the same method for the szLL const char...

if(szLL == 'NYT')

That is because MM is of type "char" and so is 'B'. On the other hand,
szLL is of type "const char*" and 'NYT' is a multi-character character
constant that ends up being of type char.

Are you trying to compare strings or compare characters ?

Thanks,
--
CrayzeeWulf
Jul 23 '05 #3
On Fri, 15 Apr 2005 21:02:48 +0000, CrayzeeWulf wrote:
That is because MM is of type "char" and so is 'B'

Well 'B' is "const char"...but you get the point.

Thanks,
--
CrayzeeWulf

Jul 23 '05 #4
Thanks for the explanations Victor and CrazeeWulf... I fully understand
now. Also, thanks for the 'strcmp' function code Victor it was very
enlightening. I just tested it right now and for some reason it didn't
work... turns out the "NYT" string had an additional character which is
a blank space. I thought I was doing something wrong, or didn't
understand your code correctly, but turns out "NYT" should be "NYT "
:-)

Again, thank you both for your great help.

Best regards,
Marcus

Jul 23 '05 #5
CrayzeeWulf wrote:
'NYT' is a multi-character character
constant that ends up being of type char.

Ooops. Another mistake. Here is what the standard says (ISO/IEC 14882:200
(E):2.13.2.1):

"An ordinary character literal that contains more than one c-char is a
multicharacter literal. A multicharacter literal has type int and
implementation-defined value."

Of course, you really meant "NYT" in the first place anyways and not 'NYT'.

Later,
--
CrayzeeWulf
Jul 23 '05 #6

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

Similar topics

2
1902
by: William Payne | last post by:
Hello, consider these following two classes. A base class, class MDIChildWindow, and a class inherting from that base class, class Document. In the static base member function callback() I obtain a pointer to the child class and call the function on_mdiactivate() using this pointer. For some reason, the program executes MDIChildClass::on_mdiactivate() and not Document::on_mdiactivate(). Why? on_mdiactivate() is a virtual function in...
19
4237
by: Ross A. Finlayson | last post by:
Hi, I hope you can help me understand the varargs facility. Say I am programming in ISO C including stdarg.h and I declare a function as so: void log_printf(const char* logfilename, const char* formatter, ...); Then, I want to call it as so:
11
1956
by: j23 | last post by:
I have library (static) testlib.cpp: #include <stdarg.h> void xxx(...) { char buf; va_list args; va_start(args, buf); va_end(args); }
1
1912
by: Nick Bishop | last post by:
I have a problem where I call a method in a C++ class with a pointer which is a static member in that class. When I use a debugger, I see the pointer having a certain value, but when I step into the method (F11), the pointer has a different value and is not pointing at anything valid. The small program (complete source below) demonstrates what I am trying to achieve. The small program works perfectly, but when I incorporate this logic...
8
3049
by: Plissken.s | last post by:
I have a template function which print out the content of a list: The following compiles: void PrintInt2 (int i) { cout << i << " "; } template <class T> void printList(T& list) {
6
4620
by: RB Smissaert | last post by:
Made a C++ dll with MS VC6 and trying to call the dll from Excel VBA. This is the code in the .cpp file: #include "stdafx.h" #include <string> #include <math.h> using namespace std;
5
2265
by: Joakim Hove | last post by:
Hello, I have a function like this: /* It actually does something else .... */ void func (int size, const char ** string_list) { int i; for (i=0; i < size; i++) printf("String number %d: %s \n",i,string_list);
2
1509
by: kalyani1031 | last post by:
hi, Iam calling CPP function in C , I get the following undefined references. ./mycppinc/libmycppinc.a(cpp_file.o)(.text+0xd): In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': : undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const' ./mycppinc/libmycppinc.a(cpp_file.o)(.text+0x60): In...
61
5807
by: Ron Ford | last post by:
K&R has three different versions of qsort, and the ultimate one is supposed to be like the one in the std library. I'm trying to implement the first, which is in §4.10. I think I'm pretty close with this: void qsort(int v, int left, int right) { int i, last;
0
8379
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8019
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8251
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6674
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5839
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5418
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3873
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2391
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1223
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.