Thread: How to make a program with multiple functions run with main function at the top?

  1. #1
    Registered User
    Join Date
    Mar 2017
    Posts
    1

    Question How to make a program with multiple functions run with main function at the top?

    So basically I was working on my homework, basically completed everything, but one trick was to make the program have no warnings even with the int main(void) at the top of the program.
    I literally researched and tried almost everything but could not get it to work. Im stumped and I need yalls help!

    When I run it, it works perfectly, but showed warnings when I compiled it.

    I purposely left out code in functions to not be a victim, if you need more, let me know.

    TLDR: I need to make this run with no warnings.

    Code:
    int main(void){
            int max = 100;
            int randnums[max];
            populateArray(randnums,max);
    
            insertionSort(randnums,max);
            printArray(randnums, max);
    
    }
    
    void populateArray(int* randnums, int max){
            
    
    }
    void insertionSort(int * randnums,int max){
            swap(val1,val2);
    }
    
    void swap(int* val1, int* val2){
            
    }
    
    void printArray(int* randnums,int  max) {
            
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,658
    You need to prototype your functions before main.

    Like so
    Code:
    void populateArray(int* randnums, int max);
    void insertionSort(int * randnums,int max);
    void swap(int* val1, int* val2);
    void printArray(int* randnums,int  max);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-11-2015, 05:20 AM
  2. Modifying multiple link lists (from main) in a function
    By darkbrew7 in forum C Programming
    Replies: 3
    Last Post: 06-07-2011, 08:32 PM
  3. Replies: 3
    Last Post: 06-01-2011, 03:08 AM
  4. Program skips functions in main
    By En-Motion in forum C++ Programming
    Replies: 5
    Last Post: 02-18-2009, 09:35 PM
  5. multiple main functions
    By vurentjie in forum C Programming
    Replies: 3
    Last Post: 05-21-2008, 01:54 PM

Tags for this Thread