Hello and welcome to our community! Is this your first visit?
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
    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.

    #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]);
        //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);
            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. #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Marion, IA USA
    Thanked 84 Times in 83 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 09:26 AM.
    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