What is wrong with my sort function?
Hi,
I am creating a program which asks for ten characters, and in return it sorts them in alphabetical order. Here is the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
// sa2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
void srt(char x[]);
int main()
{
int i=0;
char temp;
char x[10]={' '};
cout<<"Enetered Order\n"<<endl;
for (i=0;i<10;i++)
{
cout<<"Enter a character: ";
cin>>x[i];
}
cout<<"\nSorted Order\n"<<endl;
srt(x);
for (i=0;i<10;i++)
{
cout<<x[i]<<endl;
}
return 0;
}
void srt(char x[])
{
int i;
char temp;
for (int i=0;i<10;i++)
{
temp=x[i];
x[i]=x[i+1];
x[i+1]=temp;
}
}
|
Can anyone please check, what is wrong with my program?
Topic archived. No new replies allowed.