0

I'm trying to load some an image with stbi_load functions like this:

stbi_load(filename, parameter2, parameter3, parameter4, parameter5);

The problem is I have the filename like this:

stbi_load("example_filename",...);

But the functions requires the first parameter to be const char*. I tried casting but it didn't load the image. I'm using Visual Studio 2017.

  • 1
    1) Please provide [mcve], with **copy-pasted** (not paraphrased) error message. 2) What does "didn't work" mean? – Algirdas Preidžius Jul 05 '19 at 16:13
  • This does sound like a runtime problem then, not a compiler issue, assuming you're not getting any compiler warnings on that line. Can you try giving it an absolute path to the image? Or setting the working directory in the project properties to the path where the image is? Or looking at the error code you're getting back from stbi_load - is it definitely file not found? - or stepping into the load code if you can to see what's going wrong? Or use something like procmon to watch the process attempt to open the file to see what it's doing wrong? – Rup Jul 05 '19 at 16:26

1 Answers1

1
stbi_load("example_filename",...);

But the functions requires the first parameter to be const char*. I tried casting but it didn't work.

String literals implicitly convert to const char* so this is not a problem. There is no need to cast it. Remove the cast and it should work unless you have another problem that you haven't shown us.

eerorika
  • 232,697
  • 12
  • 197
  • 326
  • I started out without a cast and it failed to load the image. –  Jul 05 '19 at 16:19
  • @yomag1234 Have you verified that the file exists? – eerorika Jul 05 '19 at 16:20
  • Yes, I also tried moving it in between the files to see if that's the problem, but it didn't load no matter where I put ut. –  Jul 05 '19 at 16:21
  • 2
    @yomag1234 How did you verify that the file exists? Perhaps you were mistaken. Did you verify that the file is readable? Did you verify that the file has the correct format. Did you compile without `STBI_NO_FAILURE_STRINGS`? Was there no error message at all? Regardless, there appears to be no reason to assume that the problem has anything to do with `const char*`. – eerorika Jul 05 '19 at 16:25
  • Yeah, you're right. I'll take a closer look and try to figure it out . –  Jul 05 '19 at 16:27