Search code examples
citoa

What is wrong with my itoa conversion?


Background

Im trying to determine character codes for some national diactric letters.

Problem

Is something is wrong with my code?

char a = "a"; // "a" ascii code is 97

char buffer[8];

itoa(buffer,(int)a, 10);

print(buffer); // but it prints "252" instead of "97"

Solution

  • The character code for 'a' is indeed 97, but "a" is of type char *. Single quotes ' encode characters, double quotes " encode string literals.

    Try

    char a = 'a';