Jump to content

Help em C


markoni
 Share

Recommended Posts

? 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

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;
}
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.