-1

I am currently trying to read from multiple directories, but when I set the path using a %s (has a saved array of all the file locations) it will not read.

SDL_Surface* image = SDL_LoadBMP("D:\\UltimateModManager\\mods\\%s\\.umm\\icon.bmp", currentmod[i - 1]);

It prints the location just fine onto the console, yet it will not read my image. But if I set a true path, it does oddly enough.

1 Answers1

2

You seem to have a misconception that %s in a string has some special property. It doesn't. The % character is just a literal %. The context in which you've used it the way you seem to want is passing it to printf, where it's *still just a literal % in the string, but the string is a format string that printf interprets to know what types of arguments to expect and how to format them, rather than a string to be printed itself.

To achieve what you want here, you need to use an additional buffer array to construct your string in, and use something like:

snprintf(buf, sizeof buf,
         "D:\\UltimateModManager\\mods\\%s\\.umm\\icon.bmp",
         currentmod[i - 1]);

then pass buf as the argument to SDL_LoadBMP.

R.. GitHub STOP HELPING ICE
  • 208,859
  • 35
  • 376
  • 711