473,399 Members | 3,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Dynamic allocate string array

Hi,

I have a char * mFileList[];

how can i dynamically allocate it to save some strings?

Thanks in advance
Feb 28 '08 #1
7 6942
On Feb 28, 2:53 pm, huohaod...@gmail.com wrote:
Hi,

I have a char * mFileList[];

how can i dynamically allocate it to save some strings? I'd like to allocate it to and array of POINTERS to char strings, some thing like char *mFileList[1000]

Thanks in advance
Feb 28 '08 #2
hu********@gmail.com wrote:
I have a char * mFileList[];

how can i dynamically allocate it to save some strings?
std::vector<std::stringmFileList;

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Feb 28 '08 #3
On Feb 28, 3:12 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
huohaod...@gmail.com wrote:
I have a char * mFileList[];
how can i dynamically allocate it to save some strings?

std::vector<std::stringmFileList;

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
I tried char * mFileList[] = new char[index]; but got a syntax error.
Feb 28 '08 #4
hu********@gmail.com wrote:
[..]
I tried char * mFileList[] = new char[index]; but got a syntax error.
char **mFileList = new char*[size];

But let me reiterate, do NOT presume managing dynamic memory is
easy or recommended. Try to stick to standard containers before
you learn enough. Do

std::vector<std::stringmFileList(size);

It's basically all you need, trust me.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Feb 28 '08 #5
On Feb 28, 3:46 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
huohaod...@gmail.com wrote:
[..]
I tried char * mFileList[] = new char[index]; but got a syntax error.

char **mFileList = new char*[size];

But let me reiterate, do NOT presume managing dynamic memory is
easy or recommended. Try to stick to standard containers before
you learn enough. Do

std::vector<std::stringmFileList(size);

It's basically all you need, trust me.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Thanks a lot for the help
Feb 28 '08 #6
hu********@gmail.com wrote:
Hi,

I have a char * mFileList[];
This is an invalid declaration. You must either have an initializer
list or give that array a dimension.
how can i dynamically allocate it to save some strings?
Do what Victor said. Use the tools that have been developed to aid the
programmer.


Brian
Feb 28 '08 #7
hu********@gmail.com wrote:
Hi,

I have a char * mFileList[];

how can i dynamically allocate it to save some strings?

Thanks in advance
If possible, try std::vector<std::stringmFileList;
If not possible, try std::vector<char*mFileList;

The std::vector should be as effective as anything manaul, such as new
char*[count] and with a known value you can do:

std::vector<char*mFileList( count );
Which will create a dynamic array of count elements of char*.

Still, std::vector<std::stringis much prefered, but it really depeneds on
your code.
--
Jim Langston
ta*******@rocketmail.com
Feb 29 '08 #8

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

Similar topics

8
by: Peter B. Steiger | last post by:
The latest project in my ongoing quest to evolve my brain from Pascal to C is a simple word game that involves stringing together random lists of words. In the Pascal version the whole array was...
6
by: Materialised | last post by:
Hi Everyone, I apologise if this is covered in the FAQ, I did look, but nothing actually stood out to me as being relative to my subject. I want to create a 2 dimensional array, a 'array of...
11
by: D | last post by:
hi, i would like to know how to calculate the size of a dynamic array created using a dereference declaration like int *numbers and allocating via malloc or calloc: numbers=(int...
2
by: Richard | last post by:
Define a record structure to hold a set of test scores, number of tests, and the average score. The number of records are to be determined at runtime. Also the number of tests for each record is...
12
by: googlinggoogler | last post by:
Hi, Im new to C++ and trying to self teach myself whilst I sit at my unentertaining day job (thought i'd put that across before im accused of cheating on my homework, im 45...) Anyway I'm...
8
by: omariqbalnaru | last post by:
Is there anyway to allocate memory dynamically according to the input? For example if the user has to input his name e.g. in this case Omar Iqbal Naru is inputted by the user. How to allocate...
3
by: sunilkjin | last post by:
Hi , I am trying to alllocate a 2D array of strings and returning it to a functiion, I get a memory access error. What is wrong with the program? int main3DArray( char *** x); int main() {...
1
by: Peterwkc | last post by:
Hello all expert, i have two program which make me desperate bu after i have noticed the forum, my future is become brightness back. By the way, my problem is like this i the first program was...
18
by: welch.ryan | last post by:
Hi all, Having a problem with addressing large amounts of memory. I have a simple piece of code here that is meant to allocate a large piece of memory on a ppc64 machine. The code is: /*...
6
by: Paul | last post by:
Hi all, I have a string which I want to break into a char array, is the following way of doing this ok: const char* test = new char; test = sQuery.c_str(); and finally:
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
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,...

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.