• Wincent
    Open
  • Blog
  • Wiki
  • Snippets
  • Tags
  • Search

A short C program for printing out ASCII values interactivelyEdit

Created 9/26/2006, updated 8/26/2023
void main(void) {int c; while(c = getchar()) printf("%d 0x%02X\n", c, c);}

The same, but formatted less golfily:

#include <stdio.h>

int main(void) {
  int c;

  while ((c = getchar())) {
    printf("%d 0x%02X\n", c, c);
  }

  return 0;
}

Assuming that’s saved into a file called a.c, compile and run (on macOS) with:

clang a.c && ./a.out
  • c
  • wiki
Site
  • About
  • Blog
  • Wiki
  • Snippets
  • Tags
  • Search
External
  • GitHub
  • Twitter
  • YouTube
  • Facebook
  • LinkedIn
Colophon

Made by Greg Hurrell using React, Relay and GraphQL (with help from Git, Redis and Neovim).