0

I need to get the path of %APPDATA% in my c program, to save a file in %APPDATA%\myprogram\ How can I do that ?

Red Star
  • 265
  • 2
  • 15

1 Answers1

5

You should be able to get that information through getenv, here is an example.

#include<stdio.h>
#include<stdlib.h>

int main ()
{
    char * app_data;
    app_data= getenv ("APPDATA");

    if (app_data!=NULL)
        printf ("The appdata path is: %s",app_data);

    return 0;
}
DominicEU
  • 3,585
  • 2
  • 21
  • 32
  • That answers the OPs question (and will work almost all of the time) but is **not** the right way to do this. The OP should instead use SHGetKnownFolderPath. – Harry Johnston Jan 31 '16 at 22:19
  • Can you give an example of using SHGetKnownFolderPath in C (because All I can find on that is in C++) – Red Star Feb 01 '16 at 19:44