Reverse String without Built-In Functions

Ram Pothuraju
This program is to reverses a String without built-in functions .


This program uses the concept of Arrays for the same. And doesnt use built in string functions.
Can be made into C or C++ program

#include<iostream.h>
#include<conio.h>
char* rev(char *a,int n);
void main()
{
char *a;
char *b;
int n,m;
clrscr();
cout<<"Enter a string of chars ";
cin>>a;
cout<<"Enter the characters in the string";
cin>>m;
cout<<"The string is "<<a<<endl;
cout<<"Array size is "<<n;
b=rev(a,m);
cout<<"Revers of the array is "<<b;
getch();
}
char* rev(char a[],int n)
{
int i,j;
char *tmp;
for(i=0,j=n-1;i<n;i++,j--)
{
tmp[i]=a[j];
cout<<tmp[i]<<endl;;
}
tmp[i]=a[n];
return tmp;
}

Tags

Post a Comment

0Comments

Post a Comment (0)