Skip to content

Commit 93d8ce3

Browse files
authored
Update BinarySearchRecursion.c
added input validation for size
1 parent ec3c2e7 commit 93d8ce3

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

BinarySearchRecursion.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ int binarySearchRecursive(int arr[], int left, int right, int target, int *count
2121
int main() {
2222
int size;
2323
printf("Enter the size of the sorted array: ");
24-
scanf("%d", &size);
24+
if (scanf("%d", &size) != 1 || size <= 0) {
25+
printf("Invalid input for size. Please enter a positive integer.\n");
26+
return 1;
27+
}
2528

2629
int array[size];
2730
printf("Enter %d elements in sorted order for the array:\n", size);

0 commit comments

Comments
 (0)