| | |
sorting characters in a string... help!!!!
Please support our C++ advertiser: Intel Parallel Studio Home
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++ calculator char char* class classes code coding compile console conversion database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





