473,563 Members | 2,681 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

string arrays and pointers

3 New Member
Hi, umm i actually have a problem in one of my labs.
I am trying to make a library, where the user initializes multiple books(Object bookType), and their names are saved into a dynamic array called books[1]. i was trying to use pointers to expand the array's size each time a new book is defined.
while running my compiler breaks and gives me an error that "memory access violation" , i do realize that the mistake is because a string doesnt have a consistent size. So how can i know what size each of the names occupies in memory so that i can move that number of locations in memory ????

my code is :

// pb is pointer of books
//NOfB is number of books


Expand|Select|Wrap|Line Numbers
  1. void bookType::setName(string n)
  2. {    name = n;
  3.     cout << n;
  4.     system("pause");
  5.     *(pb+NOfB)= n;
  6.     NOfB++;
  7.     system("pause");
  8.  
  9. }
thank you so much in advance :)
Apr 9 '11 #1
1 1228
whodgson
542 Contributor
Try using a vector instead of an array. load it`s elements with 'push_back'
Apr 10 '11 #2

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

Similar topics

3
4838
by: Java script Dude | last post by:
Some programmers prefer to stay with native level data structures such as string arrays instead of using Object based data structures such as ArrayList. From and efficiency point of view. Are string arrays the most efficient way of dealing with static tabular data such as query returns? or is it more efficient to use a Recordset type data...
6
12750
by: ASPfool | last post by:
Hello everyone, Please help me before I throw my computer out of the window: I'm working on a web application in classic ASP (vbscript), which is making calls to some webservices. The calls are made using SOAP - i installed the SOAP3 toolkit on my windows 2k server to enable this. The webservice calls are returning String Arrays which I...
5
3742
by: swarsa | last post by:
Hi All, I realize this is not a Palm OS development forum, however, even though my question is about a Palm C program I'm writing, I believe the topics are relevant here. This is because I believe the problem centers around my handling of strings, arrays, pointers and dynamic memory allocation. Here is the problem I'm trying to solve: ...
2
1267
by: zlf | last post by:
Hi, This there any existing alorgithm in .NET that can extract the common element in two string arrays to another string array; usage: string a = { "1","2","3" }; string b = { "1" }; string c = extractCommonElement ( a , b );
9
2086
by: jerry.upstatenyguy | last post by:
I am really stuck on this. I am trying to write a string array containing a "word" and a "definition" to a class called Entry. Ultimately this will end up in another class called dictionary. No, this is not a homework assignment. In fact it was a question on my class midterm that everyone bombed. Unfortunately we never covered this in...
0
1137
by: Caffiend | last post by:
Hello again! I am still having problems with the code under the title "newbie woes", but I have moved on for now to another exercise. The book has asked me to write a program that will use two string arrays to select a toy out of a bag, a ball or cube in 1 of four colours. There should also only be one ball and cube for each colour, which is...
1
9407
by: Rick Knospler | last post by:
I am trying to convert a vb6 project to vb.net. The conversion worked for the most part except for the fixed length strings and fixed length string arrays. Bascially the vb6 programmer stored all form data in a fixed length structure that is written direct to disk. I need to load the existing files, into a fixed length structure to...
8
1798
by: rsaikamesh | last post by:
Hi All, In my c++ application, I need to use 60 string arrays with the size of 16. If I create this much of arrays, will the performance of my application be affected?
0
1449
by: =?Utf-8?B?YWlhaG1lZA==?= | last post by:
I am trying to call a Webservice written in Java from .NET C# client. I am getting the following error : Exception Details: System.Web.Services.Protocols.SoapException: Server was unable to process request. --There is an error in XML document (1, 1128). --The specified type was not recognized: name='string',...
6
3438
by: tshad | last post by:
I am looking for a way to combine 2 string arrays. I am trying to get a list of files from 2 directories and combine them: string strFiles; string strFiles2; strFiles = Directory.GetFiles(Settings.ArchiveFilePath, "*.*"); strFiles2 = Directory.GetFiles(Settings.ExceptionFilePath, "*.*");
0
7882
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. ...
0
7945
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...
0
6244
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...
1
5481
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...
0
5208
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...
0
3634
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...
0
3618
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2079
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
1
1194
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.