472,784 Members | 823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,784 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 6913
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: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.