getc() vs fgetc() – What are the major differences?

From the Advanced Programming in Unix Environment: … The difference between getc and fgetc is that getc can be implemented as a macro, whereas fgetc cannot be implemented as a macro. This means three things: The argument to getc should not be an expression with side effects. Since fgetc is guaranteed to be a function, we can take its address. This allows us to pass the address of fgetc as … Read more

Reading \r (carriage return) vs \n (newline) from console with getc?

\n is the newline character, while \r is the carriage return. They differ in what uses them. Windows uses \r\n to signify the enter key was pressed, while Linux and Unix use \n to signify that the enter key was pressed. Thus, I’d always use \n because it’s used by all; and if (x == ‘\n’) is the proper way to test character equality.