Thread: conflicting types in functions

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    4

    Question conflicting types in functions

    can any one please explain the reason for the error: conflicting types in 'qsort'
    in the following code

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    void qsort(int *p,int array_size)
    {
    int i,j,temp;
    for(i=0;i<array_size-1;++i)
    for(j=0;j<array_size-1-i;++j)
    {
       if(p[j]>p[j+1])
       {
         temp=p[j];
         p[j]=p[j+1];
         p[j+1]=temp;
       }
    }
    }
    
    void main()
    {
    int *a;
    int i,p;
    printf("enter the number of elementts");
    scanf("%d",&p);
    a= (int *) malloc(p*sizeof (int));
    printf("enter the elements");
    for(i=0;i<p;i++)
    scanf("%d",(a+i)); 
    qsort(a,p);
    for(i=0;i<6;i++)
    printf("%d ",*(a+i));
    printf("\n");
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    25,809
    Before we go further:
    • qsort is the name of a standard library function available via <stdlib.h>. Therefore, you should rename your qsort function.
    • You should indent your code properly.
    • Unless you have special reasons, declare the return type of main to be int.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Dec 2011
    Posts
    4
    Oh, what a coincidence....i used a standard library function..
    thanks a lot !!!!
    i am new to c programming..........y we must declare return type of main to be as int (in most cases authors use this)?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    25,809
    Quote Originally Posted by prince777
    thanks a lot !!!!
    You're welcome

    Quote Originally Posted by prince777
    y we must declare return type of main to be as int
    Read the FAQ on main() / void main() / int main() / int main(void) / int main(int argc, char *argv[])
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. stuck with conflicting types for
    By rukshan in forum C Programming
    Replies: 3
    Last Post: 09-27-2011, 01:00 AM
  2. error: conflicting types for 'functions'
    By solarbit in forum C Programming
    Replies: 3
    Last Post: 07-25-2011, 08:07 AM
  3. Conflicting Types for function
    By tomeatworld in forum C Programming
    Replies: 1
    Last Post: 12-06-2010, 11:43 AM
  4. Conflicting types???
    By kwikness in forum C Programming
    Replies: 11
    Last Post: 10-07-2007, 11:53 PM
  5. conflicting types for...
    By dudinka in forum C Programming
    Replies: 3
    Last Post: 05-14-2005, 07:03 AM