当前位置: 技术问答>linux和unix
Linux下C语言文件编程问题
来源: 互联网 发布时间:2015-12-22
本文导语: 有在study文件夹中两个文件夹分别是:program和log 我要在program里面写一个程序把产生一个日志文件log.xml到log文件里面; 怎么实现? 在Windows里面可以如下实现(但linux下不行): File *log; log=fopen("..//log//log.xml","wt");...
有在study文件夹中两个文件夹分别是:program和log
我要在program里面写一个程序把产生一个日志文件log.xml到log文件里面;
怎么实现?
在Windows里面可以如下实现(但linux下不行):
File *log;
log=fopen("..//log//log.xml","wt");
我要在program里面写一个程序把产生一个日志文件log.xml到log文件里面;
怎么实现?
在Windows里面可以如下实现(但linux下不行):
File *log;
log=fopen("..//log//log.xml","wt");
|
FILE *file;
GList *section_list, *line_list;
IniSection *section;
IniLine *line;
if (!(file = fopen (filename, "wb")))
return FALSE;
section_list = ini->sections;
while (section_list)
{
section = (IniSection *) section_list->data;
if (section->lines)
{
fprintf (file, "[%s]n", section->name);
line_list = section->lines;
while (line_list)
{
line = (IniLine *) line_list->data;
fprintf (file, "%s=%sn", line->key, line->value);
line_list = g_list_next (line_list);
}
fprintf (file, "n");
}
section_list = g_list_next (section_list);
}
fclose (file);
GList *section_list, *line_list;
IniSection *section;
IniLine *line;
if (!(file = fopen (filename, "wb")))
return FALSE;
section_list = ini->sections;
while (section_list)
{
section = (IniSection *) section_list->data;
if (section->lines)
{
fprintf (file, "[%s]n", section->name);
line_list = section->lines;
while (line_list)
{
line = (IniLine *) line_list->data;
fprintf (file, "%s=%sn", line->key, line->value);
line_list = g_list_next (line_list);
}
fprintf (file, "n");
}
section_list = g_list_next (section_list);
}
fclose (file);
|
Windows里面可以如下实现(但linux下不行):
File *log;
log=fopen("..//log//log.xml","wt");
FILE *fopen(const char *path, const char *mode);
log=fopen("..//log//log.xml","w+");
没有t?
The fopen function opens the file whose name is the string pointed to by path and associates a stream with it.
The argument mode points to a string beginning with one of the following sequences (Additional characters may follow these
sequences.):
r Open text file for reading. The stream is positioned at the beginning of the file.
r+ Open for reading and writing. The stream is positioned at the beginning of the file.
w Truncate file to zero length or create text file for writing. The stream is positioned at the beginning of the
file.
w+ Open for reading and writing. The file is created if it does not exist, otherwise it is truncated. The stream is
positioned at the beginning of the file.
a Open for appending (writing at end of file). The file is created if it does not exist. The stream is positioned
at the end of the file.
a+ Open for reading and appending (writing at end of file). The file is created if it does not exist. The initial
file position for reading is at the beginning of the file, but output is always appended to the end of the file.
File *log;
log=fopen("..//log//log.xml","wt");
FILE *fopen(const char *path, const char *mode);
log=fopen("..//log//log.xml","w+");
没有t?
The fopen function opens the file whose name is the string pointed to by path and associates a stream with it.
The argument mode points to a string beginning with one of the following sequences (Additional characters may follow these
sequences.):
r Open text file for reading. The stream is positioned at the beginning of the file.
r+ Open for reading and writing. The stream is positioned at the beginning of the file.
w Truncate file to zero length or create text file for writing. The stream is positioned at the beginning of the
file.
w+ Open for reading and writing. The file is created if it does not exist, otherwise it is truncated. The stream is
positioned at the beginning of the file.
a Open for appending (writing at end of file). The file is created if it does not exist. The stream is positioned
at the end of the file.
a+ Open for reading and appending (writing at end of file). The file is created if it does not exist. The initial
file position for reading is at the beginning of the file, but output is always appended to the end of the file.
|
linux下也差不多
|
一样的,log=fopen("../log/log.xml", "a+");
|
我记得Linux的文件描述符似乎是int型的哦
int *log;
log=fopen("..//log//log.xml","wt");
不知道这样行不行
int *log;
log=fopen("..//log//log.xml","wt");
不知道这样行不行
|
int log;
log=fopen();
无缓区型
log=fopen();
无缓区型
|
楼主理解有些错误吧!!。。
文件描述符是整数,你那FILE *fp是文件指针
有open 与fopen 两函数 !!!
参数:前者用文件描述符,后者是用*fp (我是用的UNIX 不晓得LINUX。。。)
文件描述符是整数,你那FILE *fp是文件指针
有open 与fopen 两函数 !!!
参数:前者用文件描述符,后者是用*fp (我是用的UNIX 不晓得LINUX。。。)
|
都是c,会有什么区别
|
没什么区别