// ex_ch7_2.c
#include <stdio.h>

int main(void)
{
	int char_count = 0;
	char ch;

	// blurb
	printf("Enter characters, use # to end.\n");

	// input loop
	while ((ch = getchar()) != '#')
	{
		// a new char - increase counter
		char_count++;

		// if the char is not a newline
		if (ch != '\n')
		{
			// display the code
			printf("%c = %d ", ch, ch);
		} else {
			// it is a newline - display it, reset counter
			// and continue to next iteration
			printf("%c", ch);
			char_count = 0;
			continue;
		}

		// check whether we already printed 8 characters in the column
		if ((char_count % 8) == 0)
		{
			// we did - insert newline & reset counter
			printf("\n");
			char_count = 0;
		}
	}
	return 0;
}