I want two create two functions that can do this. So one function takes a character, for example the character a and returns the integer 97. The other function takes this integer 97 and returns the character a. I know this can be done by using the ASCII codes of these characters, but then it wouldn't work for characters like é, à, ö. Can this be done using unicode or another way?
For example:
int character_to_integer(char c) {
convert character to integer and return
}
Input: character_to_index('é');
Output: 102 (for example)
char integer_to_character(int i) {
convert integer to character and return
}
Input: integer_to_character(102);
Output: é
I want to do this with it: have an array, so for example int my_array[5] with all elements set to NULL at the start. Then for example, index 0, 3 and 4 (which correspond to a, d and e for example) are set to something other than NULL then I want to loop over it and build a string based off the which indexes aren't NULL, like so:
void build_string_from_array(int my_array) {
char buffer[16];
char c;
for (i = 0; i < 5; i++) {
if (my_array[i] != NULL) {
c = integer_to_character(i);
buffer[i] = c;
}
}
buffer[5] = '\0';
printf("%s\n", buffer);
}
Output: ade
Note, this is just an example, and I know there is probably something wrong with it, but it's just to get my point across. I know this can be done with ASCII codes, where all the characters are only 1 char, but how can this be done so that characters like é, that are seen as 2 chars would also work?
If it's not clear what I mean just ask me and I'll elaborate some more.