How to get character code (ASCII and Unicode) in C

3 Answers

0 votes
#include <stdio.h>

int main(void) {
    char ch = 'a';

    printf("%d", ch);

    return 0;
}



/*
run:

97

*/

 



answered Jan 20, 2023 by avibootz
edited Apr 15 by avibootz
0 votes
#include <stdio.h>

int main() {
    char ch = 'a';
    
    int ascii = (unsigned char)ch;
    
    printf("%d\n", ascii);   

    return 0;
}



/*
run:

97

*/

 



answered Jan 20, 2023 by avibootz
edited Apr 15 by avibootz
0 votes
#include <wchar.h>
#include <stdio.h>

int main() {
    // Unicode
    wchar_t wc = L'Ω';
    
    printf("UTF-16 code unit: %u\n", wc);   
    
    return 0;
}



/*
run:

UTF-16 code unit: 937

*/

 



answered Apr 15 by avibootz
...