Quantcast
Viewing all articles
Browse latest Browse all 22079

I'm using Linux, compiling with gcc, getting error: warning: implicit declaration of function ‘fopen_s’, can someone help me fix this?

I'm trying to write a simple edge detection program in c. I'm using Red Hat Enterprise Linux Server 7.7 (Maipo), and gcc version 4.8.5.

This is the start of the code:

#include <stdio.h>

#define size 200

int _tmain(int argc, _TCHAR* argv[])
{
    char filein[size] = "./image.bmp";

    FILE *fin;

    fopen_s(&fin, filein, "rb");

return 0;

}

I initially, had a lot of problems with _TCHAR* so eventually I replaced it with just char, I have no idea if this will be a problem later, but at least it compiled and got rid of those errors. Now I'm getting the implicit declaration warning. I've tried to fix it by adding other #include's.

I've tried to fix it with:

#include <stdio.h>
#include <errno.h>
#include <string.h>

#define size 200

int main(int argc, char* argv[])
{
    char filein[size] = "./image.bmp";

    FILE *fin;

    fopen_s(&fin, filein, "rb");

return 0;

}

But, I'm still getting the same warning, can someone tell me what I'm doing wrong?

Thanks.

Thank you so much, this works!

#include <stdio.h>

#define size 200

int main(int argc, char* argv[])
{

    char filein[size] = "./image.bmp";

    FILE *fin;

    fin = fopen(filein, "rb");

return 0;

}

Viewing all articles
Browse latest Browse all 22079

Trending Articles