pourriez vous me donner un exemple de programme avec setenv et getenv
merci
Version imprimable
pourriez vous me donner un exemple de programme avec setenv et getenv
merci
setenv() n'est pas une fonction standard.Citation:
Envoyé par amelhog
Quand à getenv(), c'est pas bien compliqué :
http://www.die.net/doc/linux/man/man3/getenv.3.html
Qu'est-ce que tu ne comprends pas ?
affiche :Code:
1
2
3
4
5
6
7
8
9
10
11
12
13 #include <stdio.h> #include <stdlib.h> int main() { printf("%s\n", getenv("PATH")); setenv("HELLO", "Hello world", 0); printf("%s\n", getenv("HELLO")); return 0; }
~/test$ ./test
/opt/java/jdk1.5.0_05/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games
Hello world
Citation:
Envoyé par ciol2.6.12
Code:
1
2
3
4
5
6 main.c: In function `main_': main.c:12: error: implicit declaration of function `setenv' main.c:12: warning: nested extern declaration of `setenv' main.c:17:2: warning: no newline at end of file Process terminated with status 1 (0 minutes, 0 seconds)
Comportement indéfini. Merci de bien lire la doc de la fonction avant de l'utiliser...Code:
1
2
3
4
5
6
7
8
9
10
11 #include <stdio.h> #include <stdlib.h> int main() { printf("%s\n", getenv("PATH_")); return 0; }
Citation:
RETURN VALUE
The getenv() function returns a pointer to the value in the environment, or NULL if there is no match.
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #include <stdio.h> #include <stdlib.h> int main(void) { static char const VAR[] = "PATH_"; char *var = getenv(VAR); if (var != NULL) { printf("%s\n", var); } else { printf("The '%s' environment variable is not defined\n", VAR); } return 0; }
setenv, est une fonction BSD, ça a été dit dans un post il n'y a pas longtemps, la fonction recherche du forum existe ...