fixed formatting errors

This commit is contained in:
Roland W-H 2022-05-29 21:17:44 +01:00
parent 2c9ce86b76
commit f7ffa91c11
3 changed files with 17 additions and 10 deletions

View File

@ -114,11 +114,20 @@ 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;
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);

View File

@ -14,4 +14,3 @@ int lsrch(int* arr, int n, int target)
return -1;
}

View File

@ -9,4 +9,3 @@
int lsrch(int* arr, int n, int target);