Red Star
Red Star

Reputation: 265

How to get %APPDATA% path in C (windows 7)

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

Upvotes: 0

Views: 295

Answers (1)

DominicEU
DominicEU

Reputation: 3631

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;
}

Upvotes: 5

Related Questions