what did i do wrong help me fix this

Need help with the backward string part please help me fix this code thank you




// 1. Length of a C-String
int stringlength(char charray[])
{
int length = 0;
// Get the data
// the character string will be passed to function as a parameter
// Determine the length of the C-String
// Use a loop to iterate over the elements and look for '\0'
do {
if ( charray[ length ] == '\0' )
break;
++length;
} while (true);

return length;

}

//2. Backward String
int getthestring( char charray[], int maxsize)
{
int length = 0;
cout << "please enter a single word less than" << maxsize;
cout << "characters in length\n";
cin >> charray;
length = stringlength (charray);
return length;
}
int reversethestring( char charray[], int minsize)
{
int length = 0;
cout << "please enter a single word more than" << minsize;
cout << "characters in length\n";
cin >> charray;
length = stringlength (charray) - 1;
return length;
}
void backwardstring()
{
char charray[256] = {'\0'};
int arrsize = 0;


//2.1 get the data: a function that prompts user for a string
getthestring( charray, 256 - 1);
//2.2 use the data: create a string of backward characters
reversethestring( charray, 256 - 1);
//2.3 output the data: send the backward to the standard output
cout << charray << endl;
}



int main()
{
backwardstring();
return 0;
}
Are you required to use functions?
Try this?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string name;
	string reverse_name;
	cout << "Enter name: ";
	getline(cin, name);
	
	for(int i = name.length()-1; i >= 0; i--)
	{
		reverse_name += name.at(i);
		
	}
	cout << reverse_name << endl;
	
	return 0;
}
Last edited on
Topic archived. No new replies allowed.