| | |
sorting characters in a string... help!!!!
Thread Solved
![]() |
•
•
•
•
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(); }
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.
"Jedenfalls bin ich überzeugt, daß der Alte nicht würfelt."
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
![]() |
Similar Threads
- Sorting Strings (Java)
- Bubble sorting (Java)
- Hi, everyone I need Help in MIPS random string (Assembly)
- Open In New Window Php (PHP)
- Vectors, Functions, and Sorting... oh my! (C++)
- sorting an array of string (C)
- sorting 2d arrays (C)
Other Threads in the C++ Forum
- Previous Thread: Segmentation Default Error when Initializing Class object
- Next Thread: quick synax question
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ char class classes code coding compaitibility compile console conversion count delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error factorial file floatingpoint forms fstream function functions game givemetehcodez graph guessing gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker loop looping loops map math matrix maze memory multiple net news node oop output parameter payment pointer problem program programming project projectassignmenthelp protection python random rank read recursion reference rpg skills string strings temperature template test text text-file tree url variable vector video win32 windows winsock wordfrequency wxwidgets





