Zelaron Gaming Forum

Zelaron Gaming Forum (http://zelaron.com/forum/index.php)
-   Tech Help (http://zelaron.com/forum/forumdisplay.php?f=329)
-   -   Quicksort (http://zelaron.com/forum/showthread.php?t=34307)

deadlock75 2004-11-02 04:25 PM

Quicksort
 
I almost got this program to work but I just got two errors on them I labeled the error where it is causing it on turbo C++.


#include <stdio.h>

#define MAXNUMS 2000
void quicksort (int *a, int lft_bnd, int rt_bnd);
void swap (int a[], int i, int j);
void print_arr (int a[], int nums);

main (int argc, char * argv[])
{
char filenm[20];
int dataarray [MAXNUMS];
int num_nums=0, i, eof;
FILE *fopen(), *flpt;
void print_arr (int dataarray[], int num_nums);
if (argc !=2)
{
printf ("proper invocation: pgm datafile\n");
exit(0); //call to undefined function 'exit' in function main[int, char **]
}
flpt = fopen(argv[1],"r"); //extra parameter in call to fopen() in function main[int, char **]
if (flpt == NULL)
{
printf ("Open failed, check data filename\n");
exit(1);
}
eof = fscanf(flpt, "%d", &dataarray[num_nums]);
num_nums=num_nums+1;
while (eof >0)
{
eof = fscanf(flpt, "%d", &dataarray [num_nums]);
num_nums=num_nums+1;
if (num_nums>2000)
{
printf ("too many numbers, increase array size and recompile\n");
exit (2);
}
}
num_nums=num_nums-1;
printf ("sorting %d numbers \n", num_nums);
printf ("the unsorted numbers are:");
print_arr (dataarray, num_nums);
quicksort (dataarray, 0, num_nums-1);
printf ("the sorted numbers are: ");
print_arr (dataarray, num_nums);
}

Demosthenes 2004-11-02 04:27 PM

#include <stdlib.h>

and why do you have fopen() as a file pointer?

deadlock75 2004-11-04 04:58 PM

Oops
 
Quote:

Originally Posted by mjordan2nd
#include <stdlib.h>

and why do you have fopen() as a file pointer?


So all I need is to add that library in there #include <stdlib.h> and take the pointer out right?


All times are GMT -6. The time now is 03:00 AM.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
This site is best seen with your eyes open.