Search code examples
cformat-specifiers

Format specifier in C: can %s can store integer values?


Can %s format specifier that stores string consisting of sequence character store sequence of integers? If yes..can you please explain?


Solution

  • Numbers are represented with characters anyway, so YES you can read a number with the "%s" specifier and store it in a char[] array, after that you can change the representation of the character string to a numeric variable (a binary representation) with the use of atoi() or strtol().