mirror of
https://github.com/RolandWH/ceesort.git
synced 2025-06-07 23:01:32 +01:00
Compare commits
No commits in common. "38deb15d4dbf3a3364b286b6a5e7f177ed6e1652" and "ecdcdc2821a10177d3c6474407a7a16e601a4164" have entirely different histories.
38deb15d4d
...
ecdcdc2821
@ -23,7 +23,6 @@ int bsrch(int target, int* arr, size_t n)
|
||||
{
|
||||
if (arr[mid] == target) found = true;
|
||||
if (start == end && !found) return -1;
|
||||
if (mid == end && !found) return -1;
|
||||
else if (arr[mid] < target)
|
||||
{
|
||||
start = mid + 1;
|
||||
|
@ -13,7 +13,6 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
inline void quit_err(const char* msg)
|
||||
@ -52,28 +51,20 @@ int main(int argc, char** argv)
|
||||
}
|
||||
int n = argc - 1;
|
||||
|
||||
/*
|
||||
* The line:
|
||||
* buffer[strcspn(buffer, "\n")] = 0;
|
||||
* Strips trailing newline, so "2\n" becomes "2"
|
||||
*/
|
||||
|
||||
char choice_str[16];
|
||||
printf(
|
||||
"1. Binary search\n"
|
||||
"2. Bubble sort\n"
|
||||
"Please pick a mode of operation: "
|
||||
);
|
||||
fgets(choice_str, 16, stdin);
|
||||
choice_str[strcspn(choice_str, "\n")] = 0;
|
||||
scanf("%s", choice_str);
|
||||
|
||||
// TODO: Add checking that number is in range
|
||||
while (!isint(choice_str))
|
||||
{
|
||||
printf("Sorry but you must enter a number between 1 and 2\n");
|
||||
printf("Try again: ");
|
||||
fgets(choice_str, 16, stdin);
|
||||
choice_str[strcspn(choice_str, "\n")] = 0;
|
||||
scanf("%s", choice_str);
|
||||
}
|
||||
int choice = atoi(choice_str);
|
||||
|
||||
@ -81,12 +72,11 @@ int main(int argc, char** argv)
|
||||
{
|
||||
char target_str[16];
|
||||
printf("Enter number to search for: ");
|
||||
fgets(target_str, 16, stdin);
|
||||
target_str[strcspn(target_str, "\n")] = 0;
|
||||
scanf("%s", target_str);
|
||||
while (!isint(target_str))
|
||||
{
|
||||
printf("Sorry but you must enter a whole number, try again: ");
|
||||
fgets(target_str, 16, stdin);
|
||||
scanf("%s", target_str);
|
||||
}
|
||||
int target = atoi(target_str);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user