I was wondering if anyone can help me:
I need to turn the output of the system command : whoami
into a variable.
Example:
char *a;
a = system("whoami");
printf("username = %s",a);
I have tried a few methods such as printing the commands output to a text file like: whoami >> output.txt
and than making the program read from that file, however i am encountering errors through that method. I also consider that method to be a little messy and unnecessary as im positive that there must be a way within C to let me do this.
This question may be a duplicate so please label as necessary(but also answer if capable)
Thanks a lot :)