So, I am trying to make the program completely from scratch (without libraries), and I have a function that is very ugly:
int parseUnsignedInt ( char * ch, unsigned int * ui ) { ui = 0;
Part of its ugliness stems from the fact that I need a way to associate char actors with int egers ('0' โ 0, '1' โ 1, ..., '9'-> 9) and made an array or structures
typedef struct icpair { char cval; int ival; } icpair; icpair decmap [10] = {{'0',0}, {'1',1}, {'2',2}, {'3',3}, {'4',4}, {'5',5}, {'6',6}, {'7',7}, {'8',8}, {'9',9}}; int decmapLength = sizeof(decmap)/sizeof(icpair);
for this purpose. But looking at the value, if it even exists, takes into account the unsightly number of lines that can be compressed if there is a better way to do it in pure C. I also want it to be reliable, so no subtraction of the ASCII value, for example '9'-'ch' . Is this possible in pure C, and if so, how is this implemented?