Character Array

I have been attempting this function for the past two days and can not seem to figure it out.

void insert is called back into main with CHAR CH being inputted by the user back in main.

void insert has to record the input character into the array at INT CURRENT and shift the rest of the array elements to the right by one spot.

Help...please.




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
void insert (char text [size], int& current, char ch)
{
    
     
     int z; 
     
     
     
     if (current<size-1)
     {
        for (z=size-1; z>current; z--);
           {
            text[z]=text[z-1];
            text[z]=ch;                           
            current++;
            }
             
         
         }
        
        
     else
     cout << "Error, insertion is not allowed" << endl;             
         
     
     
     
 }
One problem is that size is not an argument so unless it's a global, you won't be able to use it in your if or for statements.
Topic archived. No new replies allowed.