Results 1 to 2 of 2

Thread: Newbie Help

  1. #1

    Thread Starter
    Lively Member Crazy_bee's Avatar
    Join Date
    Jul 2001
    Location
    Fitchburg
    Posts
    90

    Arrow Newbie Help

    I am brand new at C and just messing aound can anyone tell me what is wrong with this code:
    #include <stdio.h>
    void sort_array(int a[])

    int main()
    {
    int the_array[5]={9,5,0,2,1};
    sort_array(the_array);
    return 0;
    }

    void sort_array(int a[])
    {
    int i, j, temp;

    for (i=0; i < 5; ++i)
    {
    for(j = 4; j > i; --j)
    {
    if (a[j-1] < a[j])
    {
    temp = a[j-1];
    a[j-1] = a[j];
    a[j] = temp;
    }
    }
    }
    printf("%d",a[0]);

    }
    these are the errors when building:
    C:\My Documents\Class\GradedAssign.c(5) : error C2085: 'main' : not in formal parameter list
    C:\My Documents\Class\GradedAssign.c(5) : error C2143: syntax error : missing ';' before '{'
    C:\My Documents\Class\GradedAssign.c(8) : warning C4098: 'sort_array' : 'void' function returning a value
    C:\My Documents\Class\GradedAssign.c(12) : error C2084: function 'void __cdecl sort_array(int *)' already has a body

    Thanks
    Don't ever Ginop before you Ginip

  2. #2
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    You forgot a ;

    PHP Code:
    #include <stdio.h> 
    void sort_array(int a[]); 
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width