我试图使用 read() 函数来获取用户输入,但我在文档中唯一能找到的是关于从文件中读取的内容,这是在 Linux c 语言中。我还想使用 write() 向控制台显示一些内容。
有人知道这是怎么做到的吗?
最佳答案
but the only thing I can find in the documentation is regarding reading from files
别担心,标准输入是一个文件。
char buf[128];
read(STDIN_FILENO, buf, sizeof(buf));
I also want to use write() do display something to the console.
我不再重复了。
const char *s = "Hello World!\n";
write(STDOUT_FILENO, s, strlen(s));
关于c - 使用 read() 获取用户输入而不是 scanf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14635827/