Hi everyone, I have been writing a program that resembles the "WHICH" program of LINUX for the Windows Platform. It accepts a program from User Input and tries to look for it in the registry. But unfortunately, there is a lot of memory corruption and i cannot even add lines of codes. Thanks for your help.

#include <windows.h>
#include <iostream.h>
#include <string.h>
int main()
 char rgvalue[100];
 LONG lnResult;
 DWORD Type;
 DWORD size1;
 HKEY hKey;

 char reg[100];
 strcpy(reg, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\");
 char prog[100];

 cout << "Enter: ";
 cin >> prog;

 char all[100];
 strcat(all, reg);
 strcat(all, prog);

 if (strcmp(prog, "iexplore.exe") == 0)
    strcpy(rgvalue, "%ProgramFiles%\\intern~1");
 else if (strcmp(prog, "cmd.exe") == 0)
    strcpy(rgvalue, "%systemroot%\\system32");

      if(ERROR_SUCCESS != RegOpenKeyEx(HKEY_LOCAL_MACHINE, all, 0, KEY_ALL_ACCESS, &hKey) )
        cout << "Program does not Exist in Registry\n";
        return 0;

     RegQueryValueEx(hKey, "Path", NULL, &Type, (LPBYTE)rgvalue,&size1);

 /*strcpy(prog, "explorer.exe");
 strcat(prog, " ");
 strcat(prog, rgvalue);

 cout << rgvalue << endl;

 return 0;

Maybe you should try to initialize "all" variable before strcat
char all[100] = "";
or change
strcat(all, reg);
strcpy(all, reg);