I created a folder "progfiles" on the desktop and then created an empty document named "newfile.txt" in it. After that I wrote a program to open and read write newfile.txt but on running error occured on checking errno it gave error "no such file or directory", my part of the program is:
fdr = open("Desktop/progfiles/newfile.txt",O_RDONLY,0666);
if(fdr == -1)
{
printf("Error:Failed to open\n");
perror("open:");
}
Why is it? What is the mistake I've made.
您需要包括完整的文件路径或open()
的相对路径
int fdr=open("/home/<User>/Desktop/progfiles/newfile.txt",O_RDONLY,0666);
如前所述,您要么需要包含完整的文件路径,要么要确保可执行文件位于文件所在位置的正确文件夹中,例如您给open()
的路径是"Desktop/progfiles/newfile.txt"
,以确保可执行文件位于Desktop
的父文件夹中。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.