If you just want to print it without any error checking, then you could do something like this:
Code:
#define printglade() printf("%s/hello.glade",getenv("HOME"))
Since getenv() can return NULL, this is probably not a good idea.
If you need to return a string:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *getGlade(void);
int main(void)
{
char *szGlade = getGlade();
if(szGlade)
{
printf("Glade directory: <%s>\n",szGlade);
free(szGlade);
}
else perror("Unable to retrieve Glade directory.");
return 0;
}
char *getGlade(void)
{
char *homeDir,*temp = "/hello.glade",*szReturn = NULL;
homeDir = getenv("HOME");
if(homeDir)
{
szReturn = malloc(strlen(homeDir) + strlen(temp) + 1);
if(szReturn)
{
strcpy(szReturn,homeDir);
strcat(szReturn,temp);
}
}
return szReturn;
}