Thread: putting output of system("whoami"); into a variable?

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    2

    putting output of system("whoami"); into a variable?

    hey everyone, ive been using c for about 4 days now, and just about getting used to it, i am trying to write a program under linux that puts the output of whoami into a variable and compares it with what the user inputs, I have tried all I can think of, and as im an inexperienced programmer, that isnt much, if anyone can help me, please do, all help no matter how small it will be appreciated.
    thank you for your time.

    BMS.
    Last edited by BMS; 07-02-2004 at 03:50 PM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Pipe it to a text file, open it, read it, use it, close it, remove it.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,665
    Or perhaps,

    Code:
    FILE *fp = popen( "whoami", "r" );
    Then read it as if it were a regular text file - say using fgets()
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Jul 2004
    Posts
    2
    thank you all for your help it was much appreciated.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 03:08 PM
  2. Use of variable
    By alice in forum C Programming
    Replies: 8
    Last Post: 06-05-2004, 07:32 AM
  3. why this output?
    By dredre in forum C Programming
    Replies: 4
    Last Post: 05-08-2004, 04:09 PM
  4. Store command output into a variable.
    By Kevin.j in forum C Programming
    Replies: 7
    Last Post: 09-29-2002, 11:44 AM
  5. Variable Allocation in a simple operating system
    By awkeller in forum C Programming
    Replies: 1
    Last Post: 12-08-2001, 02:26 PM