Access file's info in MINIX

This is a discussion on Access file's info in MINIX within the Linux Programming forums, part of the Platform Specific Boards category; I want to make a new command in Linux(Minix) in C, for printing some info in the screen. The info ...

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    11

    Access file's info in MINIX

    I want to make a new command in Linux(Minix) in C, for printing some info in the screen. The info is located in the file /etc/passwd and other files.
    The info is names logged in, in the system and other...
    I can use system() to open the file with vi editor but i don't know how to save something written in the file in a variable, so i can use it.
    Anyway, i don't know if any of these is right. If you have any other ideas, please help.

  2. #2
    Registered User
    Join Date
    Jun 2007
    Posts
    11
    Can i use fscanf() to access the file?
    For example the first line of the file may be: Zuko956:92555:something
    How can i store Zuko956 in a variable so i can use it?

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    You use the standard C file manipulation API, fopen(), fgets() and fclose(). Then you split the lines you read along the colons and you have the individual fields.

    Or you could use the actual passwd info API, like getpwent(), if MINIX supports it.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    Registered User
    Join Date
    Jun 2007
    Posts
    11
    Thanks once more!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Prevent access (FILES)
    By gavra in forum C Programming
    Replies: 34
    Last Post: 06-19-2008, 05:13 AM
  2. accessing files over wireless network
    By BobMcGee123 in forum Tech Board
    Replies: 4
    Last Post: 07-29-2006, 02:25 PM
  3. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 10:46 AM
  4. Multiple Cpp Files
    By w4ck0z in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 01:41 PM
  5. Folding@Home Cboard team?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 398
    Last Post: 10-11-2005, 08:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21