1
file * fp = fopen()
file * fd = ????
我想用*fd
来编写*fp
之前打开的文件。C文件操作问题
我该怎么办呢?
添加一些,这个问题的关键是使用另一个指针来做到这一点。请参阅* fd是不同的指针。我希望我明确这一点。
file * fp = fopen()
file * fd = ????
我想用*fd
来编写*fp
之前打开的文件。C文件操作问题
我该怎么办呢?
添加一些,这个问题的关键是使用另一个指针来做到这一点。请参阅* fd是不同的指针。我希望我明确这一点。
file* fd = fp;
如果我理解正确的话,当然。
使用fwrite
,fputc
,fprintf
或fputs
,这取决于你需要什么。
随着fputc
,你可以把一个char
:
FILE *fp = fopen("filename", "w");
fputc('A', fp); // will put an 'A' (65) char to the file
随着fputs
,你可以把一个char
阵列(串):
FILE *fp = fopen("filename", "w");
fputs("a string", fp); // will write "a string" to the file
随着fwrite
你也可以写二进制数据:
FILE *fp = fopen("filename", "wb");
int a = 31272;
fwrite(&a, sizeof(int), 1, fp);
// will write integer value 31272 to the file
随着fprintf
你可以写格式的数据:
FILE *fp = fopen("filename", "w");
int a = 31272;
fprintf(fp, "a's value is %d", 31272);
// will write string "a's value is 31272" to the file
http://www.cprogramming.com/tutorial/cfileio.html – marcog 2011-01-26 18:30:04
这是不是很清楚你想要做什么。 – sth 2011-01-26 18:32:09