Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- void sortArray(char *array);
- int main(){
- char input[30];
- char exitCondition[] = "quit";
- while(1){
- if (strcmp(input, exitCondition) == 0){
- break;
- } else{
- scanf("%s", input);
- sortArray(input);
- }
- }
- }
- void swap(char *ptr1, char *ptr2){
- char temp = *ptr1;
- *ptr1 = *ptr2;
- *ptr2 = temp;
- }
- void sortArray(char *array){
- int length = strlen(array);
- char *ptr;
- ptr = array;
- int i,j,k = 0;
- int smallest;
- for (int i = 0; i < length -1; i++){
- smallest = i;
- for(int j = i + 1; j < length; j++){
- if ((int)(*(array + j)) < (int)(*(array + smallest))){
- smallest = j;
- }
- //*(array + i) = *(array+ smallest);
- }
- swap(array+smallest, array+i);
- }
- for (int k = 0; k < length; k++){
- printf("%c", *ptr);
- ptr++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement