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
Is there somewhere a good introduction to rust for experienced programmers (with years of C++/C#/Java experience)?
Wanted to give it a t...
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
Hey everyone,
I resumed work on my Elixir <=> SQLite library (which uses a Rust NIF underneath) and I am in a need of small and we...
New
I’m trying to create a router where everything is in a collection of routes (similar to how I do my routes in expressjs). But it doesn’t ...
New
Are there any databases that require no setup (can be shipped in a small zip together with the project)?
New
Does anyone know beginner friendly Elixir/Phoenix Open source projects? For learning purpose :slightly_smiling_face:
New
If isReachable throws an IOException in Java, what is the right step to do and why?
The application, I believe, should halt the process ...
New
I wrote this code to calculate Fibonacci numbers by specifying the size. The results are correct, however the one thing that concerns me ...
New
Hi! I have clarifications (please correct me, as I mostly mix/confuse this details) with the following:
The term RAG here where it read...
New
Other popular topics
Write Elixir tests that you can be proud of. Dive into Elixir’s test philosophy and gain mastery over the terminology and concepts that u...
New
Which, if any, games do you play? On what platform?
I just bought (and completed) Minecraft Dungeons for my Nintendo Switch. Other than ...
New
Thanks to @foxtrottwist’s and @Tomas’s posts in this thread: Poll: Which code editor do you use? I bought Onivim! :nerd_face:
https://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
I ended up cancelling my Moonlander order as I think it’s just going to be a bit too bulky for me.
I think the Planck and the Preonic (o...
New
Think Again 50% Off Sale »
The theme of this sale is new perspectives on familiar topics.
Enter coupon code ThinkAgain2021 at checkout t...
New
A few weeks ago I started using Warp a terminal written in rust. Though in it’s current state of development there are a few caveats (tab...
New
Author Spotlight:
Peter Ullrich
@PJUllrich
Data is at the core of every business, but it is useless if nobody can access and analyze ...
New
Fight complexity and reclaim the original spirit of agility by learning to simplify how you develop software. The result: a more humane a...
New
Background
Lately I am in a quest to find a good quality TTS ai generation tool to run locally in order to create audio for some videos I...
New
Backend>Questions
Categories:
Sub Categories:
Popular Portals
- /elixir
- /rust
- /ruby
- /wasm
- /erlang
- /phoenix
- /keyboards
- /python
- /js
- /rails
- /security
- /go
- /swift
- /vim
- /clojure
- /emacs
- /java
- /haskell
- /svelte
- /onivim
- /typescript
- /kotlin
- /c-plus-plus
- /crystal
- /tailwind
- /react
- /gleam
- /ocaml
- /elm
- /flutter
- /vscode
- /ash
- /html
- /opensuse
- /zig
- /centos
- /deepseek
- /php
- /scala
- /lisp
- /react-native
- /textmate
- /sublime-text
- /nixos
- /debian
- /agda
- /django
- /kubuntu
- /deno
- /arch-linux
- /nodejs
- /revery
- /ubuntu
- /spring
- /manjaro
- /lua
- /diversity
- /julia
- /markdown
- /slackware








