0

Hello,

I'm trying to open file using a function in a header file and I think it works but I'm unsure if it's written as it should be. Should I use double pointer inside the FileOpen function like argv is or not? It also works without double pointers and that's why I'm asking this.

int main(int argc, char **argv)
{
    FILE *data, *result;

    FileOpen (&data, argv[1], "r");
    FileOpen (&result, argv[2], "w");
    fclose(data);
    fclose(result);

return 0;
}
int FileOpen (FILE **file, char *filename, char *mode) {
   *file = fopen (filename, mode);
    if (*file == NULL) {
		fprintf(stderr, "File not found: %s\n", filename);
		return FALSE;
    }
    return TRUE;
}

Edited by Vytautas: n/a

3
Contributors
7
Replies
9
Views
7 Years
Discussion Span
Last Post by JuhaW
0

If you want to find out if this works...write and read some data to you files.

Edited by gerard4143: n/a

0

It works. I think now I know that double pointers aren't needed.

Are you sure about that..Try run the code without double pointers.

0

Are you sure about that..Try run the code without double pointers.

Well, it works without double pointers... Why can I use a pointer or even a triple pointer to the given string (strings are the one's exluded with " " and chars with ' ', right?) while passing only "blah blah", or even a double pointer to that function... Ok, I'm passing for instance "r" to the function. There I use it as a pointer to char. Then I'm passing argv[x] which should be used as a pointer, not double one. I think that's correct?

0

Well, it works without double pointers... Why can I use a pointer or even a triple pointer to the given string (strings are the one's exluded with " " and chars with ' ', right?) while passing only "blah blah", or even a double pointer to that function... Ok, I'm passing for instance "r" to the function. There I use it as a pointer to char. Then I'm passing argv[x] which should be used as a pointer, not double one. I think that's correct?

What are you talking about, FILE **file or char *filename.

0

I think that FileOpen and fclose are not compatible . Is there function pairs FileOpen-FileClose or fopen-fclose. I have at least once meet problem using wrong closing function in C. Databuffer may not be flushed in this case.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.