Hey guys I am currently writing a code that will take the user input of a number and convert it to its hexadecimal form with the use of Stack ADT. This is what I have so far and would appreciate any help.

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "stack.h"

int main(void)
{
int num;
char alpha;
int* digit;
STACK* stack;

stack = createStack ();

printf("Please enter your integer (decimal): \n");
scanf("%d" , &num);

while(num > 0)
{
	digit = (int*) malloc (sizeof(int));
	*digit = num % 16;
	push (stack, digit);
	num = num/16;
}

while (!emptyStack (stack))
{
	digit = (int*)popStack (stack);
	
	if(*digit > 9)
	{
		if(*digit == 10)
		alpha = 'A';
		else if(*digit == 11)
		alpha = 'B';
		else if(*digit == 12)
		alpha = 'C';
		else if (*digit == 13)
		alpha = 'D';
		else if (*digit == 14)
		alpha = 'E';
		else if (*digit == 15)
		alpha = 'F';
	}
	
	printf("%c", alpha);

	else
		printf("%d", digit);	
}

destroyStack(stack);
return 0;
}

Hey guys I am currently writing a code that will take the user input of a number and convert it to its hexadecimal form with the use of Stack ADT. This is what I have so far and would appreciate any help.

With what? It's helpful to explain in full what the problem is rather than make us guess.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.