mirror of
https://github.com/RolandWH/ceesort.git
synced 2025-03-14 21:41:37 +00:00
fixed formatting errors
This commit is contained in:
parent
2c9ce86b76
commit
f7ffa91c11
@ -63,7 +63,7 @@ int main(int argc, char** argv)
|
|||||||
printf(
|
printf(
|
||||||
"1. Binary search\n"
|
"1. Binary search\n"
|
||||||
"2. Bubble sort\n"
|
"2. Bubble sort\n"
|
||||||
"3. Liniar search\n"
|
"3. Liniar search\n"
|
||||||
"Please pick a mode of operation: "
|
"Please pick a mode of operation: "
|
||||||
);
|
);
|
||||||
fgets(choice_str, 16, stdin);
|
fgets(choice_str, 16, stdin);
|
||||||
@ -112,13 +112,22 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
else if (choice == 3)
|
else if (choice == 3)
|
||||||
{
|
{
|
||||||
char target_str[16];
|
char target_str[16];
|
||||||
printf("Enter number to search for: ");
|
printf("Enter number to search for: ");
|
||||||
fgets(target_str, 16, stdin); target_str[strcspn(target_str, "\n")] = 0;
|
fgets(target_str, 16, stdin);
|
||||||
|
target_str[strcspn(target_str, "\n")] = 0;
|
||||||
while (!isint(target_str))
|
while (!isint(target_str))
|
||||||
{ printf("Sorry but you must enter a whole number, try again: "); fgets(target_str, 16, stdin);
|
{
|
||||||
|
printf("Sorry but you must enter a whole number, try again: ");
|
||||||
|
fgets(target_str, 16, stdin);
|
||||||
}
|
}
|
||||||
int target = atoi(target_str); int result = lsrch(arr, n, target); if (result == -1) puts("Value not found"); else printf("Value found at index: %d\n", result);
|
int target = atoi(target_str);
|
||||||
|
|
||||||
|
int result = lsrch(arr, n, target);
|
||||||
|
if (result == -1)
|
||||||
|
puts("Value not found");
|
||||||
|
else
|
||||||
|
printf("Value found at index: %d\n", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(arr);
|
free(arr);
|
||||||
|
@ -9,9 +9,8 @@
|
|||||||
|
|
||||||
int lsrch(int* arr, int n, int target)
|
int lsrch(int* arr, int n, int target)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < n; i++)
|
for (int i = 0; i < n; i++)
|
||||||
if (arr[i] == target) return i;
|
if (arr[i] == target) return i;
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,4 +9,3 @@
|
|||||||
|
|
||||||
|
|
||||||
int lsrch(int* arr, int n, int target);
|
int lsrch(int* arr, int n, int target);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user