- 論壇徽章:
- 0
|
#include <stdio.h>
#include <sys'/'types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#define LENGTH 100
main()
{
int sd,len;
char str[LENGTH],path;
printf ("輸入路徑\n");
scanf ("%s",&path);
sd = open("h.txt",O_CREAT |O_RDWR ,S_IRUSR | S_IWUSR,path);
if (sd)
{
write (sd,"hello",strlen("hell"));
close (sd);
}
sd = open ("h.txt",O_RDWR);
len = read (sd,str,LENGTH);
str[len]='\0';
printf ("%s\n",str);
close (sd);
}
我想知道怎么樣可以把path變量寫到sd = open("h.txt",O_CREAT |O_RDWR ,S_IRUSR | S_IWUSR,path);這句的"h.txt"里,以達到打開一個文件輸入路徑然后就可以得到變量路徑,在變量路徑里創(chuàng)建這個文件.? |
|