101
{ USER }
posts: 55
last: 09-Apr-2008
TITLE: String Reverse Algorithm
DESCRIPTION: Reversing Strings of text
Submitted: 09-Apr-2008 10:17:36 ( 38w 5d 20h ago ) Language: C++ (*.cpp *.h)
Views: 101 Lines of Code: 37 LINES
Rating:
rate: star1
star2
star3
star4
star5
dstar1
dstar2
dstar3
dstar4
dstar5  ( rated! )
  { 0.00 / 5 }
Difficulty: Intermediate
Bookmark
/* Author: 
   Date: 09-04-2008
   Filename: 
   Description: String Reverse code
   History: 
*/



# include <iostream.h>
# include <string.h>

void reverseit(char array[],int no)
{ char c; int len,x, mid=0;
	if(no==0)
	{for(len=0,x=0; array[x] !='\x0';len++,x++); }
	else
	{ len = 0; len = no; }

	mid = (len-1)/2;

	for(int i=0,j=len-1; i <=mid; i++,j--)
	{ c = array[i];
	  array[i] = array[j];
	  array[j] = c;
	}
	cout << endl<<array;
}

void main()
{ char data[80]; int nos=0;
	cout <<"enter string to reverse it  "; cin.getline(data,80);
	reverseit(data,0);
	cout <<endl<<"enter string to reverse it  "; cin.getline(data,80);
	cout <<endl<<"enter Nos to reversed "; cin >>nos;
	reverseit(data,nos);
}