#ifndef UNICODE
#define UNICODE
#endif
#include <Windows.h>
#include <cstdio>
TCHAR* getSystemVolumine()
{
TCHAR volumine[2];
TCHAR buffer[30];
GetSystemWindowsDirectory(buffer,30);
for(int i=0 ; i < 2 ; i++)
volumine[i]=buffer[i];
return volumine;
}
int main()
{
wprintf(L"Your system volumine letter%s\n",getSystemVolumine());
system("pause");
}
I don’t have any idea what can be wrong with this code. Debugging showed neither errors nor warnings, but the output is:
Your system volumine letter
Press any key to continue...
You are returning a pointer to a local variable, when the function has returned, that variable no longer exsits
A string for wprintf has to end with ‘\0’.