Need help with my Sorting code.
Code:
/*
|========================================|
|=== Assignment 4: Team 5 ===|
|=== Brandon ===|
|=== John ===|
|=== Adrian ===|
|========================================|
/*****************************SPECS*****************************\
|**** Write a program that uses a menu system. The program ****|
|**** will contain a character array and both a bubble ****|
|**** bubble sort and binary search. The program will sort ****|
|**** inputs and display them at the users request. ****|
\***************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define pause system("pause")
#define cls system("cls")
#define SIZE 500
#define flush fflush(stdin)
//Prototype Functions:
void displayArray(char c[], int counter);
void displayEnd();
void displayError();
void displayIntro();
void displayMenu();
void displaySpecs();
void getChar(char c[], int *counter);
void getUserChoice(char *input);
void orderZA(char array[]);
void orderAZ(char array[]);
void doTheSwitch(char array[], char i, char *switchMade);
main(){
char characters[SIZE]={0}, input=' ';
int counter = 0, i;
displayIntro();
displaySpecs();
do{
displayMenu();
getUserChoice(&input);
switch(input){
case 'A': //Add a character to the array
getChar(characters, &counter);
break;
case 'B':
orderAZ(characters);
break;
case 'C':
orderZA(characters);
break;
/* case 'D': //Search for a character
break;*/
case 'E': //Display the array
displayArray(characters, counter);
break;
case 'Q': //Quit
input='Q';
break;
default:
displayError();
break;
} //End of Switch
cls;
}while(input!='Q'); //End of do
displayEnd();
pause;
}//End of main
void displayArray(char c[], int counter){
int i=0;
cls;
printf("|****************************************|\n");
printf("|****\t |Array Inputs|\t ****|\n");
printf("|****************************************|\n\n");
if(counter==0)
printf("****Please Input Characters To Store\n");
else
for(i=0; i<counter; i++)
printf("===========++\t %i. %2c ++===========\n", i+1, c[i]);
printf("\n");
pause;
}//End of displayOutput
void displayEnd(){
printf("|****************************************|\n");
printf("|****\t Thank You for Using\t ****|\n");
printf("|****\t Our Array Program\t ****|\n");
printf("|****************************************|\n\n");
}//End of displayEnd Function
void displayError(){
cls;
printf("|*****************|\n");
printf("|*****ERROR*******|\n");
printf("|*****************|\n\n");
printf("======Please enter a vald Menu Input=====\n\n");
pause;
}//End of error Function
void displayIntro(){
printf("|========================================|\n");
printf("|===\t EXAM 4: Team 5\t ===|\n");
printf("|===\tBrandon\t\t\t ===|\n");
printf("|===\t\t John\t\t ===|\n");
printf("|===\t\t\t Adrian ===|\n");
printf("|========================================|\n\n");
}//End of displayIntro Function
void displayMenu(){
printf("|****************************************|\n");
printf("|****\t +++|MENU|+++\t ****|\n");
printf("|****************************************|\n");
printf("|\t\t\t\t\t |\n");
printf("| A. Add A Character To The Array\t |\n");
printf("| B. Put Array In Order From A-Z\t |\n");
printf("| C. Put Array In Order From Z-A\t |\n");
printf("| D. Search for a character\t\t |\n");
printf("| E. Display The Array\t\t\t |\n");
printf("| Q. Quit\t\t\t\t |\n");
printf("|\t\t\t\t\t |\n");
printf("|****************************************|\n\n");
}//End of displayIntro Function
void displaySpecs(){
char ans=' ';
printf("Would you like to view the specs?(Y or N) ");
scanf("%c", &ans);
ans=toupper(ans);
if(ans=='Y'){
cls;
printf("|********************************************|\n");
printf("|******\t PROGRAM SPECS ******|\n");
printf("/********************************************\n");
printf("|** Write a program that uses a menu **|\n");
printf("|** system. The program will contain **|\n");
printf("|** a character array and both a **|\n");
printf("|** bubble sort and binary search. **|\n");
printf("|** The program will sort inputs and **|\n");
printf("|** display them at the users request **|\n");
printf(" ********************************************/\n\n");
printf("To view the menu...\n");
pause;
flush;
cls;
}//End if
else
flush;
cls;
}//End of displaySpecs Function
void getChar(char c[], int *counter){
cls;
printf("|****************************************|\n");
printf("|****\t Type A Character(s)\t ****|\n");
printf("|****************************************|\n\n");
printf("====>: ");
scanf("%c", &c[*counter]);
flush;
(*counter)++;
}//End of getSentence
void getUserChoice(char *input){
printf("Enter Your Choice: ");
scanf("%c", input);
flush;
*input=toupper(*input);
}//End getUserChoice Function
void orderAZ(char array[]){
int i, bottom;
char switchMade;
bottom = 0;
do {
switchMade = 'N';
for(i=0; i < bottom; i++) {
if(array[i] > array[i+1])
doTheSwitch(array, i, &switchMade);
} // end for
bottom--;
}while(switchMade == 'Y');
return;
} // end of orderAZ Function
void orderZA(char array[]){
int i, bottom;
char switchMade;
bottom = SIZE - 1;
do {
switchMade = 'N';
for(i=0; i < bottom; i++) {
if(array[i] < array[i+1])
doTheSwitch(array, i, &switchMade);
} // end for
bottom--;
}while(switchMade == 'Y');
return;
} // of orderZA
void doTheSwitch(char array[], char i, char *switchMade) {
int temp;
temp = array[i];
array[i] = array[i+1];
array[i+1]= temp;
*switchMade = 'Y';
} // end function doTheSwitch