Thread: Problem on my base-8 converter program...

  1. #1
    Addicted to the Internet netboy's Avatar
    Join Date
    Dec 2001
    Posts
    158

    Arrow Problem on my base-8 converter program...

    Code:
    #include <stdio.h>
    #include <conio.h>
    #include <math.h>
    #define STACKSIZE 100
    
    typedef int Item_t;
    
    typedef struct{
    	Item_t number[STACKSIZE];
    	int Top;
    }Stack_t;
    
    void InitializeStack(Stack_t *S);
    int EmptyStack(Stack_t S);
    int FullStack(Stack_t S);
    void Push(Item_t num, Stack_t *S);
    void Pop(Stack_t *S, Item_t *num);
    
    int main()
    {
    	Stack_t S;
    	Item_t num;
    
    	double count=0,i;
    	double c,decimal;
    	int temp;
    
    
    	InitializeStack(&S);
    
    	printf("Enter a base8 number :");
    	scanf("%lf",&num);
    
    	for(i=0;i<num;i++){
    		if(num<pow(10,i)){
    			c=num/pow(10,i-1);
    			if(c==8 || c==9)
    				printf("Error!!");
    			else{
    				Push(c,&S);
    				count++;
    			}
    		}
    		temp=pow(10,i-1);
    		num=num%temp;
    	}
    
    	printf("\n\nCount : %lf",count);
    
    	printf("\n\nThe result of Pop: \n");
    
    	for(i=0; i<count; i++)
    	{
    		Pop(&S, &c);
    		putch(c);
    		decimal+=c*pow(8, i);
    	}
    
    	printf("\n\nThe equivalent decimal number   : %lf\n\n", decimal);
    
    		
    
    
    
    
    
    return 0;
    }
    
    void InitializeStack(Stack_t *S)
    {
    	S->Top=0;
    }
    
    int EmptyStack(Stack_t S)
    {
    	return(S.Top==0);
    }
    
    int FullStack(Stack_t S)
    {
    	return (S.Top==STACKSIZE);
    }
    
    void Push(Item_t num, Stack_t *S)
    {
    	if(FullStack(*S))
    		printf("\nERROR: Stack overflow!\n");
    	else
    	{
    		S->number[S->Top]=num;
    		++(S->Top);
    	}
    }
    
    void Pop(Stack_t *S, Item_t *num)
    {
    	if(EmptyStack(*S))
    		printf("\nERROR: Empty stack.\n");
    	else
    	{
    		--(S->Top);
    		*num=S->number[S->Top];
    	}
    }
    The error occured on the num=num%temp; line... it says 'Pop' cannot convert parameter 2 from 'double*' to 'int*'...

    Can anybody please help me!!!

    Thanks in advance!!!
    It's unfulfilled dreams that keep you alive.

    //netboy

  2. #2
    Registered User
    Join Date
    Jul 2002
    Posts
    45
    You've defined Item_t as an int and c as a double. When you use the address, I think you are attempting an illegal type conversion, hence the error (plus all the warnings about losing data).

    If you need to do this, you need to cast either Item_t as a double, or c as an int.

    Or, better yet, maybe you can define them all as the same type.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem w/ doubles in friend's program
    By mkylman in forum C Programming
    Replies: 16
    Last Post: 11-22-2008, 10:45 AM
  2. Problem with my program i cant figure out...
    By youareafever in forum C Programming
    Replies: 7
    Last Post: 11-01-2008, 11:56 PM
  3. I have finished my program, one problem
    By sloopy in forum C Programming
    Replies: 4
    Last Post: 11-29-2005, 02:10 AM
  4. Program problem
    By Birdhaus in forum C++ Programming
    Replies: 6
    Last Post: 11-21-2005, 10:37 PM
  5. Problem with Program not Quitting
    By Unregistered in forum Windows Programming
    Replies: 20
    Last Post: 06-11-2002, 11:06 PM