Search code examples
arrayscfunctionascii

How to convert a character chain into a ASCII


I would like to know how I could transform a character string to an ASCII value, such as "12ASD132 hello" in its ASCII values

a greeting,


Solution

  • To answer your first question: all C implementations I have ever seen store their characters in ASCII, so if your implementation is like that too, you can simply print each character in the string as an integer:

    #include <stdio.h>
    
    int main() {
      const char * str = "12ASD132 hello";
      for (const char * p = str; *p; p++) {
        printf("%d\n", *p);
      }
    }