I am getting hung up on how to get a piece of data into a char array the way it is being handled, here is a few snippets in order to help show what I'm trying to do.
a call is made - myQueue.addItem("green");
which goes to this - QueueItem *pQI = new QueueItem(pData, ++mNodeCounter);
and QueueItem looks like this - class QueueItem {
-
public:
-
QueueItem(char *pData, int id){mNodeID = id;
-
mpNext = 0;};
-
-
void setNext(QueueItem *pItem);
-
QueueItem getNext(){return *mpNext;};
-
void printData(){ cout << mData << endl;};
-
-
private:
-
char mData[30];
-
int mNodeID;
-
QueueItem * mpNext;
-
};
I'm trying to get the "green" into mData and I'm getting confused on how to do this.
I tried doing mData = &pData, but that wasn't the right way. So out of guessing I tried mData = pData, and mData = *pData none of which worked.
Pointers are still my weakest area in c++. And I've never had the text initiated in the function like this before. I think this is all the code that is needed to show what I'm trying to accomplish but if more of it is needed let me know. Thanks for any help.
5 1490 gpraghuram 1,275
Recognized Expert Top Contributor
Try copying the value to mData and you can achieve what u need
Raghuram
So out of guessing I tried mData = pData, and mData = *pData none of which worked.
Yes, it will as soon as you start using C++ string objects instead of C-style arrays.
Also, you have built a 30 byte limit into your class. That means all items are 30 bytes of they only need 3 and items larger than 30 can't be used. There should be no hard-coded assumptions.
Thanks, I was trying to see if I could do it without a string but if that's the only way to do it I will go that route. But is that also saying there is NO way to get it into a predefined character array then.
But is that also saying there is NO way to get it into a predefined character array then.
Not true. You just need to know how to do that and how to not exceed the 30 character limit, etc. By the time you write all the protective code to manage that array you will have re-written most of the string class.
Arrays are the C internal containers. They are in C++ to be compatible with C but arrays are very low-level and should not be used in C++ unless you have a real technical reason for using them that you can write down on paper.
Alright that makes sense to me, thank you
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Paul Rubin |
last post by:
I'm writing a Windows program that needs to store some user files.
The logical place to store them is in "Application Data", right?
Is there a good way to find the correct location of that directory,
preferably without any C extensions? It's ok if the directory is
found at installation time rather than runtime, and bdist_wininst does
have a way to find it from a post-installation script. The trouble is
that the post-installation...
|
by: David Lozzi |
last post by:
I am using an upload util and I was told I need this option,
enctype="multipart/form-data", in my FORM tag. How do I reference the other
form fields within the form from ASP?
THanks,
--
David Lozzi
Associated Business & Technology Group
www.associatedbtg.com
|
by: Jon Davis |
last post by:
I recently learned how to do an <OBJECT> alternative to <IFRAME> in current
browsers using:
<object id="extendedhtml" type="text/html" data="otherpage.html" width="250"
height="400"></object>
My question is how do I access the document DOM of this object in
Javascript? For example, "alert(extendedhtml.innerHTML);" doesn't work and
produces an unknown error. I'd like to both read and write to the document's
body element's innerHTML...
|
by: alederer |
last post by:
Hallo!
I have a table tstest(ts char(13) for bit data constraint a unique).
This column is filled in a trigger with generate_unique().
In a application (CLI), I have the values of this column as timestamp
representation: e.g.: select timestamp(ts) from tstest
1
|
by: Jerry |
last post by:
I have an off-the-shelf app that uses an Access database as its
backend. One of the tables contains a field with an "OLE Object"
datatype. I'm writing some reports against this database, and I
believe this field contains data I need. When I view the table in
datasheet view, all I can see in this field is the string "Long
binary data".
So, I've got the problem of needing to extract data from this
field, but I don't know what format...
| |
by: jensen bredal |
last post by:
I need to keep track on user "session data" while still turning session off
as
i do not want users login to expire?
Thanks
JB
|
by: Alex Maghen |
last post by:
Hi. I had previously installed VS2005 beta 1. I carefully followed all the
steps (I thought) to deinstall it and then installed beta 2. According to the
documentation, the "Data" directory which was to be a "special" directory in
the docroot of an ASP.NET app, has been renamed to "app_data". That's a GOOD
thing because you guys were using up too many normal words for reserved
purposes. Anyway, the problem is that I have a "Data" directory...
|
by: Sanders Kaufman |
last post by:
I'm converting my table-based layouts to css-positioned divs - but the
ONLY reason I'm doing it is because it's *considered* a best practice.
I don't really see where anything goes hinky when tables are used - but
I'm doing it anyway because the HTML and CSS specs says to reserve
tables for tabular data.
So as I convert my login widgit to a css thing, I'm saying to myself -
hey, this form is most certainly "tabular data" - even if it...
|
by: hsriat |
last post by:
I have a page working on Ajax. The problem is, after doing many changes using Ajax (like uploading, changing name, adding to favorites etc), the status bar starts behaving unexpectedly. Even when nothing is being transfered, it displays Transferring data from localhost... and that too continuously. The progress bar also shows that its working, and its all green (filled).
It doesn't even occur on a particular action. Its just random.
This is...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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...
|
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,...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |