My task is to get an input, print out the character and the ASCII value, and to present them each 8 for 1 line. For every input I’m typing I’m getting also the value of the newline character and I don’t want to print it.
This is my code:
#include <stdio.h>
int main()
{
char ch;
int count = 0;
printf("please type an input:\n");
while ((ch = getchar()) != '#')
{
++count;
printf("%c=%d ", ch, ch);
if (count%8 == 0) printf("\n");
}
}
You can use another
getchar()right after reading the first one:Or you can use scanf() and rewrite the loop equivalently: