View Full Version : Help: Compiler Error: Expected expression...

02-20-2013, 07:38 AM
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;

02-22-2013, 09:23 AM
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.