problem with -> notation and using a "general" header file

This is a discussion on problem with -> notation and using a "general" header file within the C Programming forums, part of the General Programming Boards category; Hey guys, I am trying to get a grasp on using the '->' notation which I think, I slowly do ...

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    38

    problem with -> notation and using a "general" header file

    Hey guys,
    I am trying to get a grasp on using the '->' notation which I think, I slowly do understand. However, in the CheckString function, where I am trying to assign three different things to different pointers, I get errors. The file has a 3 digit number, a boat name (can consist of more than one name - not the name of the class though) not longer than 30 chars long, and a boat type which is represented as a string but given as a enum in the header.

    The errors I had are as follows:
    Code:
    regatta.c:27: two or more data types in declaration of `main'
    regatta.c:27: function definition declared `typedef'
    regatta.c: In function `CheckString':
    regatta.c:105: parse error before `Participants'
    regatta.c:107: parse error before `int'
    regatta.c:107: `i' undeclared (first use in this function)
    regatta.c:107: (Each undeclared identifier is reported only once
    regatta.c:107: for each function it appears in.)
    regatta.c:107: parse error before `)'
    regatta.c:115: parse error before `strcpy'
    regatta.c:125: warning: passing arg 1 of `strcpy' makes pointer from integer wit
    hout a cast
    regatta.c:125: warning: passing arg 2 of `strcpy' makes pointer from integer wit
    hout a cast
    regatta.c: At top level:
    regatta.c:129: parse error before `->'
    line 27 is my main line. and the rest is the actual CheckString function.

    Code:
    char * CheckString( char *ptrdata )
    {
    	Boat *boatptr;
    	BoatType *Typeptr;
    
    	/*temporary variables for read strings*/
    	char *ptrSail, *ptrClassType, *ptrBoatName;
    
    	boatptr = Participants[ 0 ];
    
    	for( int i = 0; i < 80; ++i )
    	{
    		if( isdigit( ptrdata[ i ] ) != 0 )
    			strcpy( ptrSail[ i ], ptrdata[ i ] );
    
    		if( isalpha( ptrdata[ i ] ) != 0 )
    		{
    			if( strstr( ptrdata, "Gwen" )
    				strcpy( *ptrClassType, *ptrdata );
    
    			/*if boat type is Thorpe copy what follows from that point onwards*/
    			else if( strstr( *ptrdata, "Thorpe" )
    				strcpy( *ptrClassType, *ptrdata );
    			/*if boat type is Skiff copy what follows from that point onwards*/	
    			else if( strstr( *ptrdata, "Skiff" )
    				strcpy( *ptrClassType, *ptrdata );
    
    			/*else it is the boat name so copy to pointer*/
    			strcpy( *ptrBoatName, *ptrdata );
    		}		
    	}
    
    	boatptr->SailNum = ptrSail;
    	boatptr->BoatName = ptrBoatName;
    }
    Sorry if its getting too long. I just wanted to keep it as simple as possible. Thanks for your help in advance. Appreciate any kind of help.
    Ta,
    Johannes

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    38
    Thanks for that. I always muck up that strcpy syntax. Alos I just found an example that I could go something like this:
    Code:
    strcpy( someptr->ptrBoatType, ptrBoatType );
    is that possible in this manner? thanks. I ll fix up those errors.Ta,
    Johannes

  3. #3
    Registered User
    Join Date
    May 2003
    Posts
    38

    function CreateMaster redeclared?

    Do you know why it gives me those errors? I dont see where it could get them from. I have put the function prototypes back into the main .c program and changed a few things with the return types as I dont think I need them, using ptrs and linked lists.
    Here an extract of the error messages and the function that it complains the most about:
    Code:
    regatta.c:30: two or more data types in declaration of `CreateMaster'
    regatta.c:91: `CreateMaster' redeclared as different kind of symbol
    regatta.c:30: previous declaration of `CreateMaster'
    regatta.c: In function `CheckString':
    regatta.c:127: parse error before `Participants'
    regatta.c:140: warning: passing arg 1 of `strstr' makes pointer from integer wit
    hout a cast
    regatta.c:143: warning: passing arg 1 of `strstr' makes pointer from integer wit
    hout a cast
    Code:
    void CheckString( char *ptrdata )
    {
       Boat *boatptr;
       BoatType *typeptr;
    
       /*counter*/
       int i, j = 0;
    
       /*temporary variables for read strings*/
       char *ptrSail, *ptrClassType, *ptrBoatName;
    
       /*allocate space for pointers*/
       ptrSail = malloc( sizeof *ptrSail );
       ptrClassType = malloc( sizeof *ptrClassType );
       ptrBoatName = malloc( sizeof *ptrBoatName );
       boatptr = malloc( sizeof( Boat ) );
       typeptr = malloc( sizeof( BoatType ) );
    
       boatptr = Participants[ j ];
    
       for( i = 0; i < 80; ++i )
       {
          if( isdigit( ptrdata[ i ] ) != 0 )
             strcpy( boatptr->SailNum, ptrdata );
    
          if( isalpha( ptrdata[ i ] ) != 0 )
          {
             if( strstr( ptrdata, "Gwen" ) )
                strcpy( ptrClassType, ptrdata );
    
             /*if boat type is Thorpe copy what follows from that point onwards*/
             else if( strstr( *ptrdata, "Thorpe" ) )
                strcpy( ptrClassType, ptrdata );
             /*if boat type is Skiff copy what follows from that point onwards*/
             else if( strstr( *ptrdata, "Skiff" ) )
                strcpy( ptrClassType, ptrdata );
    
             /*else it is the boat name so copy to pointer*/
             strcpy( boatptr->BoatName, ptrdata );
          }
       }
       ++j;
    }
    Thanks heaps for having a look at the stuff. Ta,
    Johannes

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21