|
|
|
This code will take letters inputted and reverse them...
/* I did not make this program as an exersise so there probably is
a way to configure it to run better somehow.
*/
#include <iostream.h>
#include <string.h>
#include <conio.h>
const int M = 255; //Holds maximum word length
void con(char* array); //Prototype for con() function
void main()
{
char buffer[M] = {0}; //To hold the text
cout << "\nThis prorgam lets you enter text and it prints it out
backward.";
cout << "\n----------------------------------------------------------------\n\n\n";
cout << "Please enter your line of text (less then "<<
M << " characters): ";
cin.getline(buffer, M, '\n'); //Get line from user
con(buffer); //Send to function to be converted
cout << "\nYour modified text is: " << buffer <<
endl;
getch(); //Press any key to exit
}
void con(char* buffer)
{
int len = strlen(buffer);
char temp[M] = {0}; //Holds string temporarily
for(int c = 0,j = len-1; c < len ; c++,j--)
*(temp+c) = *(buffer+j); //Puts line entered into temporary array backwards
for(int d = 0; d < int(strlen(temp)+1); d++)
*(buffer+d) = *(temp+d); //Sets buffer equal to temp
return;
}
| Back | More |
| Home |