相关疑难解决方法(0)

我是否施放了malloc的结果?

这个问题,有人建议意见,我应该不会投的结果malloc,即

int *sieve = malloc(sizeof(int) * length);
Run Code Online (Sandbox Code Playgroud)

而不是:

int *sieve = (int *) malloc(sizeof(int) * length);
Run Code Online (Sandbox Code Playgroud)

为什么会这样呢?

c malloc casting

2318
推荐指数
27
解决办法
22万
查看次数

如何将文件指针(FILE*fp)转换为文件描述符(int fd)?

我有一个FILE *,通过电话回来fopen().我需要从中获取文件描述符,以便进行调用fsync(fd).从文件指针获取文件描述符的功能是什么?

c unix linux posix file

164
推荐指数
2
解决办法
10万
查看次数

了解fflush()的必要性以及与之相关的问题

以下是使用fflush()的示例代码:

#include <string.h>
#include <stdio.h>
#include <conio.h>
#include <io.h>

void flush(FILE *stream);

int main(void)
{
   FILE *stream;
   char msg[] = "This is a test";

   /* create a file */
   stream = fopen("DUMMY.FIL", "w");

   /* write some data to the file */
   fwrite(msg, strlen(msg), 1, stream);

   clrscr();
   printf("Press any key to flush DUMMY.FIL:");
   getch();

   /* flush the data to DUMMY.FIL without closing it */
   flush(stream);

   printf("\nFile was flushed, Press any key to quit:");
   getch();
   return 0;
}

void flush(FILE *stream)
{ …
Run Code Online (Sandbox Code Playgroud)

c fflush

13
推荐指数
1
解决办法
4万
查看次数

标签 统计

c ×3

casting ×1

fflush ×1

file ×1

linux ×1

malloc ×1

posix ×1

unix ×1