How to get windows directory in C

2 Answers

0 votes
#include <windows.h>
#include <tchar.h>

int main(void) {
    TCHAR  buf[MAX_PATH];
    UINT size = MAX_PATH;

    GetWindowsDirectory(&buf, size);

    _tprintf(_T("%s\n"), buf);
    
    return 0;
}





/*
run:

C:\WINDOWS

*/

 



answered May 12, 2022 by avibootz
0 votes
#include <windows.h>
#include <stdio.h>

int main() {
    WCHAR path[MAX_PATH];

    GetWindowsDirectory(path, MAX_PATH);

    printf("%ws\n", path);

    char ch = getchar();

    return 0;
}




/*
run:

C:\WINDOWS

*/

 



answered May 12, 2022 by avibootz

Related questions

1 answer 212 views
1 answer 231 views
1 answer 267 views
1 answer 186 views
...