VB icon

A reverse string function.

Email
Submitted on: 1/3/2015 1:20:00 AM
By: Brutus (from psc cd)  
Level: Beginner
User Rating: By 6 Users
Compatibility: Microsoft Visual C++
Views: 1613
 
     This is a simple function that I wrote to reverse a string. I'm a newbie to this language so please have a look and give feedback.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: A reverse string function.
// Description:This is a simple function that I wrote to reverse a string. I'm a newbie to this language so please have a look and give feedback.
// By: Brutus (from psc cd)
//
// Inputs:A string
//
// Returns:A reversed string
//**************************************

#include <iostream>
using namespace std;
int main()
{
	const int max = 80; //size of array
	char str[max]; //the array of characters
	int count = 0;
	int i = 0;
	
	cout << "Enter a string:\n"; //Prompt user to enter a string
	cin.getline(str,max,'\n'); //Read in the string
	
	while(str[count] != '\0')
		count++; //count the characters in the string, until a char 13 is found
	
	for(i = count; i >=0; i--) /loop from length of string to 0
	{
		cout << str[i]; /Display the reversed string
	}
	
 return 0;
}


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.