2
#include<stdio.h>
void selsort(int a[],int s)
{
    int min,temp,i,j;       
    for(i = 0; i < s ; i++)
    {
        min = 0;
        for(j = i+1 ; j < s; j++)
        {
            if(min > a[j])
            {
                min = j;
            }
        }
        temp = a[i];
        a[i] = a[min];
        a[min] = temp;
        for (j=0;j<s;j++)
        {
            printf("%d",a[i]);
        }
        printf("\n");   

    }
}
main()
{
        int i,a[5];
        int size = 5;
        printf("Enter elements of the array");
        for(i=0;i<size;i++)
        {
            scanf("%d",&a[i]);
        }
        selsort(a[5],size);
}

The error is as follows:

selsort.c:35:2: warning: passing argument 1 of ‘selsort’ makes pointer from integer without a cast [enabled by default]
selsort.c:2:1: note: expected ‘int *’ but argument is of type ‘int’

any tips on how to avoid this problem in the future will be really helpful

2 Answers 2

3

You should be calling your function like this:

selsort(a, size);

a[5] means "element at index 5" (past the end of your array, by the way: the largest legal element in int a[5] is at index 4).

You should also replace

min = 0;

with

min = i;

and use it like this:

if(a[min] > a[j]) ...
Sign up to request clarification or add additional context in comments.

1 Comment

@user1905568 You are welcome! If your problem is solved, you may want to accept an answer by clicking the check mark to indicate that you are no longer looking for an improved answer, and to earn a brand-new badge on stack overflow.
0

In the function call selsort(a[5], size); you are only passing the 5th [nonexistent] member of a. You want selsort(a, size);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.