0
#include <stdio.h>
#include <stdlib.h>
    
void quicksort(int number[25], int first, int last) {
    int i, j, pivot, temp;
    if (first < last) {
        pivot = first;
        i = first;
        j = last;
    
        while (i < j) {
            while (number[i] <= number[pivot] && i < last)
                i++;
    
            while (number[j] > number[pivot])
                j--;
    
            if (i < j) {
                temp = number[i];
                number[i] = number[j];
                number[j] = temp;
            }
        }
        temp = number[pivot];
    
        number[pivot] = number[j];
        number[j] = temp;
    
        quicksort(number, first, j - 1);
        quicksort(number, j + 1, last);
    }
}

int main() {
    int i, count, number[25];
    printf("Enter some elements (Max. - 25): ");
    
    scanf("%d", & count);
    printf("Enter %d elements: ", count);
    
    for (i = 0; i < count; i++)
        scanf("%d", & number[i]);
    
    quicksort(number, 0, count - 1);
    printf("The Sorted Order is: ");
    
    for (i = 0; i < count; i++)
        printf(" %d", number[i]);
    
    return 0;
}

This is my code so far. I am able to qsort the integers given by a user but not give an error message if uses inputs a character such as the letter p.

Jack Deeth
  • 3,062
  • 3
  • 24
  • 39
  • Does this answer your question? [Validate the type of input in a do-while loop C](https://stackoverflow.com/questions/31633005/validate-the-type-of-input-in-a-do-while-loop-c) – kaylum Feb 17 '22 at 02:04

1 Answers1

0

You can just check for invalid input and return. Like this:

for (int i = 0; i != '\0'; i++) {
    if (!isdigit(number[i]) {
        return;
    }
}

Make sure to include <stdlib.h>.

onapte
  • 217
  • 2
  • 8