Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

newii cuestion?

Posted on 2003-03-27
2
Medium Priority
?
161 Views
Last Modified: 2010-04-01
why this raise an error?

#include <iostream>
#include <stdlib.h>


int main(int argc, char *argv[])
{
   
  char **array;
 
  int i;
  i = 0;
  array[i] = new char[31];
  array[i] = "test1";
  std::cout << array[i] << std::endl;
 
  system("PAUSE");    
  return 0;
}

using mingw
0
Comment
Question by:enmaca
2 Comments
 
LVL 6

Accepted Solution

by:
GaryFx earned 200 total points
ID: 8220202
Before you can allocate new space for array[i], you must first allocate space for array.  If, for example, you want an array of ten character arrays, you could use something like:

array = new char*[10];
for (i=0; i<10; ++i) {
  array[i] = new char[31];
}

Of course, whenever you fixed length arrays like this, there's a question of whether or not they're big enough.

Gary
0
 
LVL 6

Expert Comment

by:Mafalda
ID: 8220259
Your initialization of array is incorrect.
You can use something like:

  char * array[20];
  for (i=0;i<20;++i)
    array[i]= new char[20];
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question