I want to search a file which may be present in any drives such as C:, D: etc. Using GetLogicalDriveStrings
I can able to get the list of drives but when I add anything extra for the output, I am getting a null
in the output prompt. Here is my code:
#include "StdAfx.h"
#include <windows.h>
#include <stdio.h>
#include <conio.h>
// Buffer length
DWORD mydrives = 100;
// Buffer for drive string storage
char lpBuffer[100];
const char *extFile = "text.ext";
// You may want to try the wmain() version
int main(void)
{
DWORD test;
int i;
test = GetLogicalDriveStrings(mydrives, (LPWSTR)lpBuffer);
if(test != 0)
{
printf("GetLogicalDriveStrings() return value: %d, Error (if any): %d
", test, GetLastError());
printf("The logical drives of this machine are:
");
// Check up to 100 drives...
for(i = 0; i<100; i++)
printf("%c%s", lpBuffer[i],extFile);
printf("
");
}
else
printf("GetLogicalDriveStrings() is failed lor!!! Error code: %d
", GetLastError());
_getch();
return 0;
}
I want above output as C:ext.ext D:ext.ext ...
rather I am getting text.ext
only. I am using Microsoft Visual C++ 2010 Express