- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试运行一些代码,但 fflush()
出现错误:
Invalid file descriptor. File possibly closed by a different thread
这是代码的相关部分:
fhandle = fopen("dbfile.bin", "rbc");
/* There is a valid dbfile.bin file - get file size */
_fstat(_fileno(fhandle), &file_stat);
printf("dbfile.bin size = %d\n", file_stat.st_size);
g_tpd_list = (tpd_list*)calloc(1, file_stat.st_size);
if (!g_tpd_list)
{
rc = MEMORY_ERROR;
}
else
{
fread(g_tpd_list, file_stat.st_size, 1, fhandle);
fflush(fhandle);
fclose(fhandle);
}
最佳答案
奇怪的是,这种行为似乎是由您将 'c'
模式传递到您的 fopen
调用中引起的。帮助是关于标志的:
Enable the commit flag for the associated filename so that the contents of the file buffer are written directly to disk if either fflush or _flushall is called
所以我不确定为什么它会导致它按现在的方式运行。但是,如果您删除它,fflush
调用会起作用。可能是此标志撤消 fflush
清除读取缓冲区并使其始终尝试清除写入缓冲区的能力。
关于c - fflush 在 Visual C++ 2010 上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5630616/
我认为 fsync() 在内部执行 fflush(),所以在流上使用 fsync() 是可以的。但是在网络 I/O 下执行时我得到了意想不到的结果。 我的代码片段: FILE* fp = fopen(
我有一个实现多线程网络代理的基本草图: FILE *proxy_log_file; static void SIGUSR1_handler(int sig) { (void)sig;
我遇到了 this page这说明了创建悬挂点的常见方式。 下面的代码通过返回局部变量的地址来说明悬空指针: // The pointer pointing to local variable bec
所以我写了一个测试程序,这是代码 #include #include int main(void) { int i; printf("%s", "entering\n");
有来自 cplusplus.com site 的简单代码 #include char mybuffer[80]; int main() { FILE *pFile; pFile =
我正在尝试使用以下代码将 2D 表格打印到我的终端: #include #include #include #include #include #include char getch()
我正在用 C 语言创建一个非常简单的程序执行计时器。我将在下面提供示例代码。问题是 fflush(NULL) 在以 Ctrl+C(即 SIGINT 信号)。它们有时仍会在 Estimated runn
我正在尝试用 C 语言制作一个时钟,但是屏幕没有正确清除,它只是不断地打印到一个新行。我如何不正确地使用 fflush? #include #include #include int main(
这个问题在这里已经有了答案: Using fflush(stdin) (7 个答案) How can one flush input stream in C? (8 个答案) 关闭 4 年前。 我似
我有这段代码:当第一个 child 向第二个 child 发送数据时,程序卡住了,第二个 child 做 fscanf 然后卡住了,因为他无法阅读我找不到它的原因。请帮助我找出如何确保 fflush
我很抱歉这个愚蠢的问题。我有 C 程序提示用户输入年龄和姓名然后将年龄和姓名打印到屏幕上。这是我从书上读到的练习。 这个程序: #include int main (void) { int a
我不确定我是否正确理解了 C 中刷新的工作原理。我就是无法按照多本手册和引用书中的描述让它工作。这是一个带有注释的示例: #include int main(void) { int x;
来自 std::fflush 文档(http://en.cppreference.com/w/cpp/io/c/fflush): Causes the output file stream to be
为什么 fflush(..) 对 c2 和 c0 不起作用? 如果我使用声明 c0 = 0 和 c2 = 0 它有效,但 fflush(stdin) 无效,我试着把在不同的地方但它没有用,我在 ubu
#include int main() { int test_no ,count=1,i,n,j; scanf("%d",&test_no); ffl
我开始编程并了解了以下命令fflush(stdout);。我明白为什么大多数平台都需要它,但我仍然问自己一些问题...... 1. \n 不是应该在 msys2 上缓冲吗,因为它是行缓冲的? (薄荷)
我似乎无法弄清楚这段代码有什么问题: #include #include #include #include #define MAX 100 #define TRUE 1 #define FA
#include int main() { int test_no ,count=1,i,n,j; scanf("%d",&test_no); ffl
我有以下代码, fflush(stdin); print("Enter y/n"); scanf("%c",&a); 这里,它在给出输入之前退出。看起来问题是因为它没有刷新可能包含一些垃圾字符的输入缓
因此,在 Google 上快速搜索用于清除输入缓冲区的 fflush(stdin) 会发现许多网站警告不要使用它。然而,这正是我的计算机科学教授教授全类的方式。 使用 fflush(stdin) 有多
我是一名优秀的程序员,十分优秀!