Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-20-2013, 06:38 AM   PM User | #1
shinsley
New to the CF scene

 
Join Date: Feb 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
shinsley is an unknown quantity at this point
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;
}
shinsley is offline   Reply With Quote
Old 02-22-2013, 08:23 AM   PM User | #2
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,220
Thanks: 4
Thanked 80 Times in 79 Posts
Spookster will become famous soon enough
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.
__________________
Spookster
CodingForums Supreme Overlord
All Hail Spookster
Who gave you that Ugging infraction? Yeah that's right it was me!

Last edited by Spookster; 02-22-2013 at 08:26 AM..
Spookster is offline   Reply With Quote
Reply

Bookmarks

Tags
c programming, compiler errror

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:56 PM.


Advertisement
Log in to turn off these ads.