Thread: Problem with cast

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    2

    Problem with cast

    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 *'
    Last edited by bumbleb33; 04-19-2008 at 04:09 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    ReadData( const char *ifp, <insert a type here> *length );
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    2
    What about the others?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    What about them?
    That one problem fixed results in some completely different problems.

    Think about them for a while, try and fix them, then post back if you're still stuck.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  2. Converting Double to Float
    By thetinman in forum C++ Programming
    Replies: 7
    Last Post: 06-17-2006, 02:46 PM
  3. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  4. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM
  5. Microsoft Visual C++ compiler, cast problem?
    By jonnie75 in forum C Programming
    Replies: 5
    Last Post: 11-10-2001, 08:53 AM