0
我必须做一个项目,但我遇到了问题。 我从阅读中收到一个字符串,但是当我看到缓冲区中有什么数据时,它会在文件末尾显示“\ n”。但是我不需要它来处理函数中的一个参数。从字符串中删除字符“ n”,读
我的代码:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
int main()
{
char buf[100];
read(1, buf, sizeof(buf));
printf("%s", &buf);
// If I write: "/tmp/", printf shows: "/tmp/\n"
DIR* drp = opendir(buf);
// Logically: no such file or directory
}
感谢