I tried making a program to reverse a given char[] array.
The problem: If you insert a big char array, let say, with 15 chars, a runtime error happens.
Second problem: When you type in "abcde", for example, the output will be "edcba²²²²". I can't see what is causing this.
You don't need to specify how much elements I want to allocate since I'm using dynamic memory, by the use of the keyword new. The name dynamic says it all.
And for the method. Imagine it this way:
You type in abcde.
Array text:
[0] [1] [2] [3] [4] --> int n starts with the value of 0, which is the element A. A B C D E
Array newText:
[0] [1] [2] [3] [4] --> int j starts with the value of i, since it represents the elements, it is 4. E D C B A
then you do it.
n=0, j=4;
n=1,j=3;
n=2,j=2;
n=3,j=1;
n=4,j=0;
And using the assignment operator it appropriately assigns the values.
You don't need to specify how much elements I want to allocate since I'm using dynamic memory, by the use of the keyword new. The name dynamic says it all.
Kibestar, you're crazy man! Very funny explanation of dymanic memory allocation :)
Runtime error you complain about is most probably due to what i said.
You don't need to specify how much elements I want to allocate since I'm using dynamic memory, by the use of the keyword new. The name dynamic says it all.
You must have a compiler that is reading your mind then. How exactly does the compiler know how to figure out the amount of memory to allocate?
Kibestar, you're crazy man! Very funny explanation of dymanic memory allocation :)
Runtime error you complain about is most probably due to what i said.
Why the hell would it be any different from normal static arrays if I had to say precisely how much elements I want to alocate? I don't want something fixed. It's D-Y-N-A-M-I-C.
dy·nam·ic (dī-nām'ĭk)
adj. also dy·nam·i·cal (-ĭ-kəl):
1. Of or relating to variation of intensity, as in musical sound.
2. Characterized by continuous change, activity, or progress
The original code doesn't even compile for me. It's not valid C++! How are you getting a run-time error? What compiler do you use?
I use Windows XP Home Edition SP3 2000. Compiler: Microsoft Visual C++ Express Edition 2008
It's not valid C++!
You must be using a toaster to compile this code.
You must have a compiler that is reading your mind then. How exactly does the compiler know how to figure out the amount of memory to allocate?
The compiler knows by how much chars you input! DYNAMIC, IT CHANGES!!!!! If I put 1 char, it is text[1], if I put 2, such as "ab" it will be text[2]. IT VARIES!!!!!
Why the hell would it be any different from normal static arrays if I had to say precisely how much elements I want to alocate? I don't want something fixed. It's D-Y-N-A-M-I-C.
It's dynamic in the sense that its size can be given at run time, not in the sense that its size can change. All C and C++ arrays are of fixed size.
It's true. It's not valid C++. And no, the compiler can't know at compile time what your input will be at run time.
If you're going to ask questions, you should be ready to accept the answers you're given.