Code:
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
FILE *ifp;
int *array1;
int length;
static int*
ReadData( const char *ifp, *length );
FILE *ofp;
char outputfile[100];
int main( int argc, const char *const *argv ) {
/* Get filename from command line. */
if( !(ifp = fopen( argv[1], "r") ) ) {
printf("Can't open the data file %s \n", argv[1]);
exit (1);
}
array1 = ReadData( *ifp, &length );
if( fclose(ifp) ) {
printf("File close error.\n");
}
return 0;
}
static int*
ReadData( const char *ifp, *length ) {
int size;
int ch;
int prev;
int i;
prev = '\n';
*length = 0;
size = 1;
array1 = malloc(sizeof(*array1) * size);
if( array1 == 0 ) return 0;
while( fscanf( ifp, "%d", &i ) != EOF ) {
while( *length >= size - 1 ) {
size *= 2;
array1 = realloc(array1, sizeof(*array1) *size);
if( array1 == 0 ) return 0;
}
array1[*length] = i;
(*length)++;
}
printf("The number of items is %d \n", length);
return array1;
}
I get the following errors I think it had to do with length.
Code:
:9: parse error before `*'
:25: parse error before `*'
: In function `ReadData':
:31: invalid type argument of `unary *'
:36: invalid type argument of `unary *'
:42: invalid type argument of `unary *'
:43: invalid type argument of `unary *'