titor
titor

Reputation: 35

ppm file read error using C in Visual Studio 2019 IDE

I am trying to read ppm files called bridge.ppm or retina.ppm and display them using a C program on a windows machine using Visual Studio 2019. Whenever I am trying to read the file using fopen I get an error. Here is the code for the same:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR     lpCmdLine, int nCmdShow)
{
FILE *fpt;
unsigned char   *image;
char        header[80];
int     ROWS,COLS,BYTES;
unsigned char *displaydata;
char fileName[128];
errno_t err;


if (MessageBox(NULL, L"Is this a greyscale image?", L"Greyscale", MB_YESNO) == IDYES)
strcpy(fileName,"bridge.ppm");
else
strcpy(fileName,"retina.ppm");
err= fopen_s(&fpt,fileName, "rb");
if (err)
{
    printf("error %d \n",err);
    printf("Unable to open %s for reading\n", fileName);
    exit(0);
}
}

Every time I get err 2, File Not Found Error. The project directory looks like this in the solution explorer: Project Structure as shown in solution explorer

To Debug this, I have done the following :

I am not that experienced with Visual Studio and may have missed some details. Please let me know.

Upvotes: 0

Views: 665

Answers (0)

Related Questions