473,788 Members | 2,733 Online
Bytes | Software Development & Data Engineering Community
+ 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 1490
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
11825
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...
5
19868
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
6
5266
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...
6
5116
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
8
25406
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...
5
1875
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
2651
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...
38
3313
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...
2
2730
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 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...
0
9498
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,...
0
10370
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, 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...
0
10177
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
10113
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
9969
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
8995
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...
0
5402
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...
0
5538
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2896
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.