For my homework assignment, I need to implement Horners Algorithm for converting between bases.
I have been told to use getchar() for this assignment. But I am having a problem where when I hit enter, the program doesn't terminate and just takes in more chars.
Example:
bryce> ./pa1 Enter the fromRadix:16 Enter the toRadix:2 abc abc ^C bryce> Code:
int readRadixA(int radixA) { char myChar = getchar(); int result = 0; int run = 0; while(myChar != EOF) { if(myChar == "\n") break; Horners(); myChar = getchar(); } return result; } I am not asking for help implementing Horners; I am asking for help to terminate the getchar() correctly.
^D, the EOF character of Unix shells? :) On Windows,^Zmight work in this role. You could also consider finishing your program on two\ns in a row (that is, typing an empty line).getcharreturns an int. Not a char, an int.myCharneeds to be anint.