so here the deal im pretty new at this programming lark and one of my lectures set the task of designing a puzzle block game (DONT WORRY NOT ASKING ANYONE TO DO IT).
using an array of 16 you got to rearrange to array so that its in ascending order, and one of the elements is a gap so orginally i set it to be zero, now here comes the intresting part when you reprint the block using a function you got to change the 0 to be an X so i did an if statement to rectify that problem
now i had an idea to change the int array of 16 to make it a char array and ive changed to rest of the program to allow this but the printing out of the array wont work because some of the numbers are double digit and that an char can only hold one number ie the character '12' will only print out '2' because of that fact mentioned above. i will show the code in a second but what im hoping to find out if the is a way of using some thing like atoi that will convert the integer value for the double digit numbers coz if there is no way to do that i will probably just go back to the integer array that i had in the beginning
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char print_board (char array[16]) ; //function to print out the board
char board[16] = {'1','2','3','4','5','6','8','12','9','10','7','X','13','14','11','15'};
int main (void)
{
print_board(board);
}
char print_board (char array[16])
{
int index = 0;
printf("\n\n\t");
for(index = 0;index<=15;index++)
{
if (index% 4 == 0)
{
printf("\n\t");
}
if ((board[index] >='10') && (board[index]!='X'))
printf("%c ", board[index]);
else
printf ("%c ", board[index]);
}
return board[16];
}
that is only a selected sample
also you may find that this is very similar to something that i posted before but i know now that i asked the wrong question earlier