I simply need to "write a program that reads input until encountering #. have the program print each input character and its ASCII decimal code. Print eight character code pairs per line"
I did the following code using the conio.h.
However conio is not ANSI nor is it POSIX. And I would like to make it ANSI at least. I was wondering how you could rewrite the code without the conio.h.Code:/* review #1.c */ #include <stdio.h> #include <conio.h> /* for getche() */ #include <stdlib.h> int main(void){ char ch; int chrcnt = 0; printf("Type any text and I will display your ASCII value\n\n"); while ( (ch = getche()) != '#'){ /* returns single charater automatically. meaning is not buffered not ainsi and not posix - bad*/ chrcnt++; printf(" = %d ", ch); if ( (chrcnt % 8 == 0)){ printf("\n\n"); } } printf("\n\nYou have %d characters.\n", chrcnt); getche(); return (0); }
A max of 8 characters per line must be outputed and there can be no use of pointers nor arrays. This is where I'm at in my studies. However I can not think of a way to use getchar() without incurring a newline. As far as I know getchar() is buffered right? meaning you need to press enter before it is displayed. However Pressing Enter will start a newline the opposite of my intent. How do I solve this please. What am I not looking at?Thank you, I don't know why it seems i've drawn a blank.
P.S. This is not homework. I'm self-taught and reading "The waite group's new C primer plus"