diff --git a/src/ceesort.c b/src/ceesort.c index 4430d40..1c056d1 100644 --- a/src/ceesort.c +++ b/src/ceesort.c @@ -63,7 +63,7 @@ int main(int argc, char** argv) printf( "1. Binary search\n" "2. Bubble sort\n" - "3. Liniar search\n" + "3. Liniar search\n" "Please pick a mode of operation: " ); fgets(choice_str, 16, stdin); @@ -112,13 +112,22 @@ int main(int argc, char** argv) } else if (choice == 3) { - char target_str[16]; + char target_str[16]; 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)) - { 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); diff --git a/src/lsrch.c b/src/lsrch.c index 80d2f1d..7f3f9cd 100644 --- a/src/lsrch.c +++ b/src/lsrch.c @@ -9,9 +9,8 @@ int lsrch(int* arr, int n, int target) { - for (int i = 0; i < n; i++) - if (arr[i] == target) return i; + for (int i = 0; i < n; i++) + if (arr[i] == target) return i; - return -1; + return -1; } - diff --git a/src/lsrch.h b/src/lsrch.h index 3cd5980..43093ab 100644 --- a/src/lsrch.h +++ b/src/lsrch.h @@ -9,4 +9,3 @@ int lsrch(int* arr, int n, int target); -