stat()

This is a discussion on stat() within the C Programming forums, part of the General Programming Boards category; I need someones help, i need to use the stat() command in a program that takes in a filename that, ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    27

    stat()

    I need someones help, i need to use the stat() command in a program that takes in a filename that, were the stat command show the permissions of that file, the program will keep going till you enter a null filename.

    I am stuck, i've tried looking up info on the stat, but not found any real good stuff that explains it.

    is there any brainy C/linux programmer out there that can help.
    -ali

  2. #2
    Anti-Terrorist
    Join Date
    Aug 2001
    Location
    mming, Game DevelopmentCSR >&<>&2Minimization of boolean functions, PROM,PLA design >&0>&WA, USA guitar, dogsCommercial Aviation >&>>&USAProgramming
    Posts
    742
    It's okay to post this here since it is a 'C' question but you might also want to try the 'Linux board' since is seems to be Operating system dependant. i have never seen this library function before when working with MSVC++6
    I compile code with:
    Visual Studio.NET beta2

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,588
    Which bit are you stuck on
    - reading filenames until an empty filename?
    - doing stat on the input file?
    - printing the data within the stat buffer?

    Here's the first two bits...
    Code:
    #include <stdio.h>
    #include <string.h>
    #include <sys/stat.h>
    
    int main ( ) {
        char buff[BUFSIZ];
        while ( fgets(buff,BUFSIZ,stdin) != NULL ) {
            char *nl = strchr( buff, '\n' );
            struct stat statinfo;
            int status;
            if ( buff[0] == '\n' ) break;   /* blank line entered */
            if ( nl != NULL ) *nl = '\0';   /* remove the end of line */
            status = stat( buff, &statinfo );
            if ( status == 0 ) {
                /* format data */
            } else {
                perror( "Failed to stat" );
            }
        }
        return 0;
    }
    You need to look in the manual page for the implementation specific bits of how the stat buffer is organised.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007

    stat

    i have never seen this library function before when working with MSVC++6
    It's _stat() in MSVC.

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    27
    Me's silly for not telling you i use linux to compile and write code, i try to stay clear of VSC++ 6.

    thanks for the code i will have a play

    I am right in thinking that the struct stat is already a structure, because of the call to the stat include???

    -ali

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 09-06-2007, 04:17 AM
  2. Random Number Range Problem.
    By xamlit in forum C Programming
    Replies: 11
    Last Post: 01-26-2006, 11:55 AM
  3. Capturing file stat information
    By Sue Paterniti in forum C Programming
    Replies: 3
    Last Post: 04-15-2002, 05:47 AM
  4. Shortening main
    By pdstatha in forum C Programming
    Replies: 1
    Last Post: 04-03-2002, 03:56 PM
  5. that damn stat()
    By @licomb in forum Linux Programming
    Replies: 2
    Last Post: 08-22-2001, 04:24 PM

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