Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Help: Compiler Error: Expected expression...

    I'm trying to figure out what is wrong here. I'm getting a compiler error that says I am missing an expected expression before int in two places.

    The activity required me to fix a memory Leak by adding free() to the code and it was suggested I do it inside the for loop. The stuff in orange is what I wrote and where the error is. All help is appreciated.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    #include "ithOrder.h"
    
    #define SIZE 500000
    
    int* generateArray(int size);
    
    int main(int argc, char** argv)
    {
    
        if (argc != 2)
        {
            fprintf(stderr, "Usage: %s <number of random lists to generate>\n", argv[0]);
            exit(-1);
        }
    
        //Initializes random number algorithm with arbitray number
        unsigned int iseed = (unsigned int)time(NULL);
        srand (iseed);
        
        int i;
        for (i = 0; i < atoi(argv[1]); i++)
        {
            //Generates some random array of size SIZE
            int* randArray = generateArray(SIZE);
    
            //Gets a random ithOrder number between 0 and SIZE -1
            int randNum = rand() % (SIZE - 1);
    
            //Finds that ithOrder number and prints the results
            int ithOrder = quickSelect(randArray, 0, SIZE-1, randNum);
            printf("The %5dth element of the randomly generated array is %d\n", randNum, ithOrder);
            sleep(2);
            
            for(i=0, i < atoi(argv[1]); i++;){
                free(int randNum);
            }
        }
    
        free(int* randMatrix);
        return 0;
    }
    
    int* generateArray(int size)
    {
        int i;
        int* dynArray = malloc(sizeof(int) * size);
    
        for (i = 0; i < size; i++)
        {
            dynArray[i] = rand();
        }
    
        return dynArray;
    }

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    When you call a function such as free() you don't need to include the data type of the parameter you are passing in. Also you have issues in your for loop. Look at your comma and semicolons.
    Last edited by Spookster; 02-22-2013 at 08:26 AM.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster


  •  

    Tags for this Thread

    Posting Permissions

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