0301使用open函数编写一个程序

使用open函数编写一个程序,打开或者创建一个指定的文件,带路径文件名由用户指定输入,文件名的最长长度为30.
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>

#define FLAGS O_WRONLY|O_CREAT|O_TRUNC
#define MODE S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH

int main(int argc, char argv[])
{
const char
pathname;//指向需要打开(或创建)文件的绝对路径名或相对路径名
int fd;//文件描述符
char pn[30];//pn为字符串数组,存放要打开的文件名
printf("input the pathname[<30 strings]:");//输入路径名,小于30个字符
gets(pn);
pathname=pn;
if((fd=open(pathname,FLAGS,MODE))==-1)//调用open函数
{
printf("error,open file failed!\n");
exit(1);//出错退出
}
printf("OK,open file successful!\n");
printf("fd=%d\n",fd);
return 0;
}