help here again... if i enter AaBbCc the output should be CcBbAa or cCbBaA.. but the output appears cbaCBA.. help!!! heres the code..
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
#include<search.h>
//int joke(const void* x,const void* y);
void main()
{
clrscr();
char a[100],temp;
cout<<"Enter string: ";
cin>>a;
for(int i=(strlen(a)-1);i>=0;i--)
cout<<a[i];
cout<<"\n\nLETTERS IN THE STRING: ";
for(int b=0;b<(strlen(a)-1);b++)
{
for(int c=b+1;c<(strlen(a));c++)
{
if(a[b]<a[c])
{
temp=a[b];
a[b]=a[c];
a[c]=temp;
}
}
}
cout<<a;
getch();
}
You need to clean up your coding habits -just a bit- to help yourself out, while working with it:
C++ files don't have .h, so it's <iostream>. Important to remember, since <string.h> is very different from <string>.
Also try C++'s string with built in functions of convenience.
Place your sorting method in a function to clear things up a tad.
Use newlines to space out parts of your code.
main() must return zero.
clrscr(), is that portable?
Now as Vernon recommended, just need to compare it in one case then flip it back keeping track of it with a boolean statement.
Reputation Points: 888
Solved Threads: 114
Nearly a Posting Virtuoso
Offline 1,270 posts
since Nov 2008