#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

char your_string[256];
char new_string[256];
void ReverseString();

int main()
char choice;
cout <<"Enter the string that you want to reverse: \n";
cin.getline(your_string, 256);
cout << new_string << "\n";
cout <<"Do you want to continue? Press e to exit: ";
while (choice != 'e');
return 0;

void ReverseString()
for(int i=0;i<256;(new_string[i]=0),i++);
int x = strlen(your_string)-1;
for(int y = x; y >= 0; y--)
new_string[x-y] = your_string[y];

I have this program that reverses strings but it is using Global arrays but the instructor doesnt want it like but using reference or static. Pass the string from main to the function using reference or static. Example: void ReverseString(string& st). Thank you for your help.

9 Years
Discussion Span
Last Post by Narue

>Thank you for your help.
You neglected to ask a specific question. Allow me to show you what your "question" looks like to me:

I have this program that works but my teacher wants me to do it without using globals. Do it for me and give me the code so I don't have to work. Thank you for your help.

So, why don't you go get your C++ book and read about how to pass an array as a function argument. The simplest solution is to move your global arrays into main and then pass them to your function.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.