using recursion to print an array of type char

i have a problem in recursive i need to print a character array of any size RECURSIVELY this is my code and the problem in the comment
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include<iostream>
using namespace std;
void printArrayForward(char arr[],int size)
{
   if(size==1)
   cout<<arr[0]<<" ";
   else
   {
      printArrayForward(arr,size-1);
      cout<<arr[size-1]<<" ";
   }
}

void main()
{
   int size;
   char arr []={""};
   cout<<"Please Enter The Size Of The Array ?"<<endl;
   cin>>size;
   cout<<"Please Enter The Elament of the Array :";
   for(int i=0;i<=size;i++)
   {
   cin>>arr[i];//her when i start to enter the element it never stops so this is my problem and i need a help im hopeless
   cout<<endl;
   }   
   cout<<"The Element Of The Array in Forward :";
   printArrayForward(arr,size);
   cout<<endl;
}
Line 17 is not right. If you plan to get the size of the array from input, you need to use dynamic allocation.
http://cplusplus.com/doc/tutorial/dynamic/

Also, on line 21 you should loop until size-1 as the array is meant to have only room for size elements, numbered 0 to size-1.
thaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaank you vary mach it done you are genius xD
thanks again
Topic archived. No new replies allowed.