#include <stdio.h>
#include <string.h>
FILE * BestTry();
int main()
{
char arr[] = "hello";
FILE * desc = BestTry();
fwrite(arr,1,5,desc);
fclose(desc);
}
FILE * BestTry()
{
FILE * retDesc = fopen(".\\hello.dat","w+");
return retDesc;
}
因为我在函数BestTry
中为局部变量分配了内存,所以是否可以安全地使用desc
进行任何用途?如果可以安全使用,那么原因是什么?
open
系统调用返回的文件描述符那样的东西。 - squiguy