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];
- scanf("%s", input);
- sortArray(input);
- while(strcmp(input, "quit") != 0){
- scanf("%s", input);
- sortArray(input);
- }
- }
- 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);
- }
- for (int k = 0; k < length; k++){
- printf("%c", *ptr);
- ptr++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement