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
}
感謝