low-level-io

C low-level standard-in to accept filename then printing file contents to stdout

瘦欲@ 提交于 2019-12-02 02:25:45
问题 I want to get a file name from a user via stdin, open the file with open() and assign it to a file descriptor, then print the contents of that file to stdout. This is my code, and it's not working properly. Problems: the printf("enter filename"); statement is never showing up it never opens the file; instead whatever the user inputs is printed to the screen and then the "no such file or directory" error message is printed and the program exits after the program exists i see "enter filename"

C low-level standard-in to accept filename then printing file contents to stdout

Deadly 提交于 2019-12-02 00:21:56
I want to get a file name from a user via stdin, open the file with open() and assign it to a file descriptor, then print the contents of that file to stdout. This is my code, and it's not working properly. Problems: the printf("enter filename"); statement is never showing up it never opens the file; instead whatever the user inputs is printed to the screen and then the "no such file or directory" error message is printed and the program exits after the program exists i see "enter filename" printed before the prompt in terminal CODE: { printf("Enter the filename: "); read(STDIN_FILENO,