Oct 18, 2018 at 5:35am
void In(void) //read the image
{
int i, j;
double el;
char buff[255];
stream = fopen("test.txt", "r"); //skeltonize -> newedg.txt & normal myFile1
for (j = 0; j < ny; j++) //row
for (i = 0; i < nx; i++) //col
{
fscanf(stream, "%lf", &el);
I[i][j] = el;
}
fclose(stream);
}
This is the aspect of the code and this is the error i get:
Error C4996 'fopen': This function or variable may be unsafe. Consider using fopen_s instead.
Error C4996 'fscanf': This function or variable may be unsafe. Consider using fscanf_s instead.
Oct 18, 2018 at 5:49am
If you are using Visual Studio you can #define _CRT_SECURE_NO_WARNINGS
before your #include files.
Not recommended. It is using a bomb to swat a fly. And doesn't fix the problems with the functions, you can still have buffer overruns.
OR
Use C11's fopen_s()
and fscanf_s()
function that was created to prevent buffer overruns. As suggested in the error messages.
https://en.cppreference.com/w/c/io/fopen
https://en.cppreference.com/w/c/io/fopen
Oct 18, 2018 at 6:04am
Still not working. Any other solution
Oct 18, 2018 at 9:39am
Don't use C code. Write C++ instead. Something like this should do it, assuming I is an array of some sensible type.
1 2 3 4 5 6 7 8
|
ifstream inputFile("test.txt");
for (j = 0; j < ny; j++) //row
{
for (i = 0; i < nx; i++) //col
{
inputFile >> I[i][j];
}
}
|
Last edited on Oct 18, 2018 at 9:40am