473,465 Members | 1,960 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to get this data myqueue.addItem("green") into a char array

3 New Member
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

Expand|Select|Wrap|Line Numbers
  1. myQueue.addItem("green");
which goes to this

Expand|Select|Wrap|Line Numbers
  1. QueueItem *pQI = new QueueItem(pData, ++mNodeCounter);
and QueueItem looks like this

Expand|Select|Wrap|Line Numbers
  1. class QueueItem { 
  2.     public: 
  3.         QueueItem(char *pData, int id){mNodeID = id; 
  4.            mpNext = 0;};
  5.  
  6.         void setNext(QueueItem *pItem);
  7.         QueueItem getNext(){return *mpNext;};
  8.         void printData(){ cout << mData << endl;};
  9.  
  10.     private: 
  11.         char mData[30]; 
  12.         int mNodeID; 
  13.         QueueItem * mpNext; 
  14. }; 
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.
Mar 4 '08 #1
5 1473
gpraghuram
1,275 Recognized Expert Top Contributor
Try copying the value to mData and you can achieve what u need

Raghuram
Mar 4 '08 #2
weaknessforcats
9,208 Recognized Expert Moderator Expert
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.
Mar 4 '08 #3
NoWorries
3 New Member
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.
Mar 5 '08 #4
weaknessforcats
9,208 Recognized Expert Moderator Expert
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.
Mar 5 '08 #5
NoWorries
3 New Member
Alright that makes sense to me, thank you
Mar 8 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

7
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...
5
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, --...
6
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> ...
6
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...
8
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...
5
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
7
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...
38
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...
2
hsriat
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...
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,...
1
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...
0
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...
0
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,...
0
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.