# $HOME or ~ in C



## killwin (Apr 12, 2010)

Hello,

how to open file like "/home/toto/file.alx" with "$HOME/file.alx" or "~/file.alx" in C language ?

Attention i don't want to part arguments into main !

Thanks


----------



## SirDice (Apr 12, 2010)

Not all shells understand ~ is $HOME.


----------



## graudeejs (Apr 12, 2010)

you need to read environment variables HOME


```
extern char **environ;
```
this will be pointer to (1D aka vertex) array of environment variables
It will be like *HOME=/home/user\0* (C string)


INFO from *Advanced Programming in the Unix Environment 2nd edition*


----------



## expl (Apr 12, 2010)

Or call libc's getenv(3). Simpler than parsing yourself.


----------



## killwin (Apr 12, 2010)

*Solved*

Solved, thanks.


----------

