C 将文件指针传递给函数

标签 c file function pointers

我在传递文件指针时遇到问题。如果函数内有一个带有文件指针的函数(我的代码中为 void writequest),我该如何传递它?在我放入 void writequest 之前它就可以工作了。该程序本身应该从一个充满电影名称的文件中读取,然后将它们放入另一个文件中。当然,请随时注意我的代码中的任何其他失败。

void writequest(int no)
{
    int i, j, loop_ctrl, destination;
    int movement;
    char lib[loop_ctrl+1][92];
    int write_nr[loop_ctrl], sorting[destination];
    char searching[92];
    char *c;
    FILE *watched;
    FILE *temp;
    FILE *refrom;
    FILE *reto;
    FILE *towatch;
    if(no==1)
    {
        printf("No match found.\n");
    }
    else if(no==0)
    {
        printf("Do you wish you write them into a file?\n1 - Yes\n0 - No\n");
        scanf("%d", &j);
        if(j==1)
        {
            tofile(watched, temp, refrom, reto, destination, loop_ctrl, write_nr, lib, movement);
            close(towatch, watched, temp, refrom, reto);
            remove("To_watch.txt");
            rename("temp.txt", "To_watch.txt");
        }
        else if(j==0)
        {
            printf("Alright then\n");
            close(towatch, watched, temp, refrom, reto);
        }
    }
}

最佳答案

  char *c;
    FILE *watched;
    FILE *temp;
    FILE *refrom;
    FILE *reto;
    FILE *towatch;

这些都是指针。因此,如果您在函数中调用它们,您就要求它们内部的值。那是他们的地址。除了运动。有点奇怪。

在任何人都能说出问题是什么之前,了解这些功能到底是什么至关重要。

关于C 将文件指针传递给函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14523048/

相关文章:

c - 返回寄存器中的结构 - GCC 中的 ARM ABI

c++ - 路径不对,怎么办?

java - 在 Java 中处理文件路径的最佳方式是什么?

python - 使用双回车将大文本文件分成单独的文件

引用自身的 javascript 函数

c - ap_log_error 没有登录我的 apache 模块

c++ - 我听说 i++ 不是线程安全的,++i 是线程安全的吗?

javascript - Java math.random 不会在函数内随机化?

Jquery 函数延迟

c++ - 为什么 "-1"在signed int 中是 11111111 而不是 10000001