
harwind
Selection Sort Program In C
I received this error for a binary search programme in C, despite the fact that it requested for inputs and produced the right output. The error message I received in the output window is shown below.
binarysearch.c: In function 'sort': binarysearch.c:22:5: warning:
implicit declaration of function 'bin'
[-Wimplicit-function-declaration]
bin(a,size);//invokes bin(int,int) to find element
^~~ binarysearch.c: At top level: binarysearch.c:24:6: warning: conflicting types for 'bin' void bin(int a[],int size)//finds element
using binary sort technique and return its index
^~~ binarysearch.c:22:5: note: previous implicit declaration of 'bin' was here
bin(a,size);//invokes bin(int,int) to find element
^~~
Enter size of array
How can I fix the problem?
What does the error indicate?
Why did it continue to ask for inputs after an error occurred?
I created two functions. As mentioned in this documentation, the first function, void sort(int a[],int size), used selection sort to sort the array and printed it before invoking the second function, void bin(int a[],int size), which used binary search to find an element and printed its position(index+1). The main function was then written.
The programme is as follows:
#include<stdio.h>
void sort(int a[],int size)//sorts array in ascending order
{
int min;
for(int i=0;i<size;i++)
{
for(int j=0;j<size;j++)
{
if(a[j]>a[j+1])//checks if elements at position 'i' is greater than element at position (i+1) and exchanges values if true
{
min=a[j];
a[j]=a[j+1];
a[j+1]=min;
}
}
}
printf("Sorted array:");
for(int i=0;i<size;i++)//prints sorted array
{
printf("%d ",a[i]);
}
bin(a,size);//invokes bin(int,int) to find element
}
void bin(int a[],int size)//finds element using binary sort technique and return its index
{
int key;//stores element to be found
printf("\nEnter element to be found:");
scanf("%d",&key);
int sp=0;//stores starting point which is initially 0
int ep=size-1;//stores ending point which is initially one less than size of array
int mid;//stores average of sp and ep
int count=0;//counter
printf("Occurrence is:");
while(sp<=ep)
{
mid=(sp+ep)/2;
if(a[mid]>key)//to run loop for elements that are before mid
{
ep=mid-1;
}
else if(a[mid]<key)//to run loop for elements that are after mid
{
sp=mid+1;
}
else if(a[mid]==key)//when element is found
{
printf("%d",mid+1);
count+=1;
break;//to stop the loop
}
}
if(count==0)//in case element is not found
printf("ELEMENT NOT FOUND");
}
int main()
{
int n;//stores size of array
printf("Enter size of array:");
scanf("%d",&n);
int arr[n];//creates array of size n
printf("Enter elements:");
for(int i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
sort(arr,n);//invoke sort(int,int) function which later invokes bin(int,int) function
return 0;
}
Popular Backend topics

Cross posting from HashNode.
A friend of mine is creating Uber-like app for a small company with 200 to 1000 cars. The app will operate ...
New

At work we plan to replace a totally overkill Kafka instance with a combination of SNS and SQS. I don’t want to get into a discussion on ...
New

Just done a fresh install of macOS Big Sur and on installing Erlang I am getting:
asdf install erlang 23.1.2
Configure failed.
checking ...
New

Hello and happy new year!
I would like to buy a Ruby On Rails ebook for learning purpose.
What would be the ROR equivalent of “Programm...
New

Hello everyone,
I’ve started learning Elixir and Phoenix few months ago and while I mostly grasped Elixir’s functional concepts and Phoe...
New

Background
I am trying to get a Github Action working with Windows and Bakeware because I am trying to create a release using it.
Howeve...
New

Hi,
Recommend pls your favorite learning resources in Go, with best books, podcasts etc.
New

Background
I have a phoenix application in Windows 11. Unfortunately for me, I cannot compile the application because of a dependency err...
New

Background
I have an umbrella project, where I run mix test from the root.
In one of the apps, I am mocking the File module using the Mo...
New

Hi guys!! I´m studying and got a Full stack course but the course lacked a lot of support and and info to learn as it´s a course after wo...
New
Other popular topics

I am thinking in building or buy a desktop computer for programing, both professionally and on my free time, and my choice of OS is Linux...
New

poll
poll
Be sure to check out @Dusty’s article posted here: An Introduction to Alternative Keyboard Layouts It’s one of the best write-...
New

Rust is an exciting new programming language combining the power of C with memory safety, fearless concurrency, and productivity boosters...
New

Do the test and post your score :nerd_face:
:keyboard:
If possible, please add info such as the keyboard you’re using, the layout (Qw...
New

Seems like a lot of people caught it - just wondered whether any of you did?
As far as I know I didn’t, but it wouldn’t surprise me if I...
New

Intensively researching Erlang books and additional resources on it, I have found that the topic of using Regular Expressions is either c...
New

Author Spotlight:
Karl Stolley
@karlstolley
Logic! Rhetoric! Prag! Wow, what a combination. In this spotlight, we sit down with Karl ...
New

A Brief Review of the Minisforum V3 AMD Tablet.
Update: I have created an awesome-minisforum-v3 GitHub repository to list information fo...
New

Hello,
I’m a beginner in Android development and I’m facing an issue with my project setup. In my build.gradle.kts file, I have the foll...
New

Ok, well here are some thoughts and opinions on some of the ergonomic keyboards I have, I guess like mini review of each that I use enoug...
New
Backend>Questions
Categories:
Sub Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /rails
- /js
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /emacs
- /haskell
- /java
- /onivim
- /typescript
- /svelte
- /crystal
- /kotlin
- /c-plus-plus
- /tailwind
- /gleam
- /react
- /ocaml
- /elm
- /flutter
- /vscode
- /ash
- /html
- /opensuse
- /centos
- /php
- /deepseek
- /zig
- /scala
- /sublime-text
- /textmate
- /lisp
- /nixos
- /debian
- /react-native
- /agda
- /kubuntu
- /arch-linux
- /django
- /ubuntu
- /revery
- /spring
- /manjaro
- /nodejs
- /diversity
- /lua
- /julia
- /slackware
- /c
- /markdown