undefined reference to `isDigit'

This is a discussion on undefined reference to `isDigit' within the C Programming forums, part of the General Programming Boards category; Code: eugene@eugene-laptop:~/cfiles$ cc 12.12.c /tmp/cc7U4qkP.o: In function `convertToPostfix': 12.12.c:(.text+0xd6): undefined reference to `isDigit' collect2: ld returned 1 exit status Isn't ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    182

    undefined reference to `isDigit'

    Code:
    eugene@eugene-laptop:~/cfiles$ cc 12.12.c
    /tmp/cc7U4qkP.o: In function `convertToPostfix':
    12.12.c:(.text+0xd6): undefined reference to `isDigit'
    collect2: ld returned 1 exit status
    Isn't isDigit part of the ctype header?


    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>
    
    struct stackNode {
    	char data;
    	struct stackNode *nextPtr;
    };
    
    typedef struct stackNode StackNode;
    typedef StackNode *StackNodePtr;
    
    
    void convertToPostfix( char infix[], char postfix[] );
    //isOperator completed
    int isOperator( char c );
    //precedence completed
    int precedence( char operator1, char operator2 );
    //push completed
    void push( StackNodePtr *topPtr, char value );
    //pop completed
    char pop( StackNodePtr *topPtr );
    char stackTop( StackNodePtr topPtr );
    int isEmpty( StackNodePtr topPtr );
    void printStack( StackNodePtr topPtr );
    
    
    
    int main()
    {
    	char iFix[ 10 ] = { 0 };
    	char pFix[ 10 ] = { 0 };
    
    	convertToPostfix( iFix, pFix );
    
    
    	return 0;
    }
    
    
    
    
    void convertToPostfix( char infix[], char postfix[] )
    {
    	StackNode *stack = NULL;
    	char temp[ 2 ] = ")";
    	push( &stack, '(' );
    
    /*   APPENDS ")\0" to the end of infix  */
    	strcat( infix, temp );
    
    
    	while( !isEmpty( stack ) ) {
    		if( isOperator( *infix ) ) {
    
    		}
    
    		if ( isDigit( *infix ) ) {
    			*postfix = *infix;
    			postfix += 2;
    		}
    		
    		if ( *infix == '(' )
    			push( &stack, *infix );
    
    		if ( isOperator( *infix ) ) {
    			if ( precedence( stackTop( stack ), *infix ) == 0 || precedence( stackTop( stack ), *infix ) == 1 ) {
    				*postfix = pop( &stack );
    				postfix += 2;
    				push( &stack, *infix );
    			}
    			else
    				push( &stack, *infix );
    		}
    
    		if ( *infix == ')' ) {
    			while ( stackTop( stack ) != '(' ) {
    				*postfix = pop( &stack );
    				postfix += 2;
    			}
    			pop( &stack );
    		}
    
    		++infix;
    	}
    
    }
    
    
    void printStack( StackNode *topPtr )
    {
    	while ( topPtr != NULL ) {
    		printf( "%c", topPtr->data );
    		topPtr = topPtr->nextPtr;
    	}
    
    	printf( "\n" );
    }
    
    
    int isEmpty( StackNode *topPtr )
    {
    	if ( topPtr == NULL )
    		return 1;
    	else
    		return 0;
    }
    
    
    char pop( StackNode **topPtr )
    {
    	char output;
    	StackNode *tempPtr = NULL;
    
    	output = ( *topPtr )->data;
    	tempPtr = *topPtr;
    	*topPtr = ( *topPtr )->nextPtr;
    	free( *topPtr );
    
    	return output;	
    
    }
    
    
    char stackTop( StackNode *topPtr )
    {
    	if ( topPtr != NULL )
    		return topPtr->data;
    	else
    		return ' ';
    
    }
    
    
    void push( StackNode **topPtr, char value )
    {
    	
    	StackNode *newPtr = NULL;
    	newPtr = malloc( sizeof( StackNode ) );
    	
    	if ( newPtr != NULL ) {
    		newPtr->nextPtr = *topPtr;
    		newPtr->data = value;
    
    		*topPtr = newPtr;
    	}
    }
    
    
    int isOperator( char c )
    {
    	if ( c == '+' || c == '-' || c == '*' || c == '/' || c == '^' || c == '%' )
    		return 1;
    
    	else
    		return 0;
    
    
    }
    
    
    //Determine if precedence of operator1 is greater(1), equal(0), or less then(-1) operator2
    int precedence( char operator1, char operator2 )
    {
    	int opValue[ 2 ] = { 0 };
    	char operator[ 2 ];
    	operator[ 0 ] = operator1;
    	operator[ 1 ] = operator2;
    	int i = 0;
    
    	for ( i = 0; i < 2; ++i ) {
    		switch( operator[ i ] ) {
    			case '+': case '-':
    				opValue[ i ] = 1;
    				break;
    			case '*': case '/': case '%':
    				opValue[ i ] = 2;
    				break;
    			case '^':
    				opValue[ i ] = 3;
    				break;
    			case '(': case ')':
    				opValue[ i ] = 4;
    				break;
    		}
    
    	}
    
    
    
    	if ( opValue[ 0 ] > opValue[ 1 ] )
    		return 1;
    	if ( opValue[ 0 ] == opValue[ 1 ] )
    		return 0;
    	else
    		return -1;
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,181
    The function name is isdigit, not isDigit.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    ya,C is case sensitive,that's why isDigit and isdigit are two entirely different things.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 09:18 PM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 12:45 PM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  4. C OpenGL Compiler Error?
    By Matt3000 in forum C Programming
    Replies: 12
    Last Post: 07-07-2006, 05:42 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM

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