markoni Posted May 22, 2008 at 11:03 AM Report Share #186651 Posted May 22, 2008 at 11:03 AM ? estou a construir uma shell em C para correr em linux, alguem me sabe dizer como saber o path onde estamos a trabalhar?isto é, ao abrir o program eu quero que me apareca o \root\...usuario actual"......Alguem ajuda plz? Link to comment Share on other sites More sharing options...
zedlav Posted May 22, 2008 at 02:48 PM Report Share #186716 Posted May 22, 2008 at 02:48 PM Boas. Pode se fazer de varias formas, esta e uma delas. ref getenv() : http://opengroup.org/onlinepubs/009695399/functions/getenv.html ref getlogin(): http://www.opengroup.org/onlinepubs/000095399/functions/getlogin.html #include <stdio.h> int main(){ char *va; char *lgn; lgn = getlogin(); va = getenv("PWD"); printf("%s@%s:>",lgn, va); return 0; } http://zedlav.dyndns.org Link to comment Share on other sites More sharing options...
Rui Carlos Posted May 22, 2008 at 06:49 PM Report Share #186765 Posted May 22, 2008 at 06:49 PM Parece-me que o que precisas é a função getwd (ou getcwd). Rui Carlos Gonçalves Link to comment Share on other sites More sharing options...
macwadu Posted November 25, 2008 at 04:37 AM Report Share #228537 Posted November 25, 2008 at 04:37 AM Boas, tem um exemplo de como usar a função gethostname() em c Tanks Link to comment Share on other sites More sharing options...
Rui Carlos Posted November 25, 2008 at 09:23 AM Report Share #228540 Posted November 25, 2008 at 09:23 AM Boas, tem um exemplo de como usar a função gethostname() em c Tanks #include <stdio.h> #include <unistd.h> #define LEN 40 int main() { char hostname[LEN]; if(!gethostname(hostname,LEN)) puts(hostname); else puts("Erro!"); return ; } Rui Carlos Gonçalves Link to comment Share on other sites More sharing options...
macwadu Posted November 25, 2008 at 01:41 PM Report Share #228587 Posted November 25, 2008 at 01:41 PM Obrigadão já consegui.... 😁 Agora etsou com um problema com o getlogin char login[LEN]; getlogin_r(login,LEN); puts(login); isto devia dar? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now