Find the answer to your Linux question:
Results 1 to 2 of 2
I want to find out free disk space on my system within a C/C++ program. When i am running this code : #include <stdio.h> #include <sys/vfs.h> int main() { char ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2003
    Posts
    1

    Free disk Space on the drive


    I want to find out free disk space on my system within a C/C++ program.
    When i am running this code :

    #include <stdio.h>
    #include <sys/vfs.h>

    int main()
    {
    char path[300];
    struct statfs *buff;
    int i;

    strcpy(path,"/home/alok/");
    i = statfs(path, buff);
    if (i==0)
    printf("%s \t %s\n", *buff.f_bfree, *buff.f_bavail);
    else
    printf("%s \t %d\n)", "Error occured",i);
    }

    And the result i am getting is:

    error -1

    that means there is some problem with the execution of statfs function.

    Can any body help me out what the problem is??

    Thanks
    Alok

  2. #2
    Just Joined!
    Join Date
    Nov 2003
    Posts
    7
    struct statfs sf;

    ...
    i = statfs("/path", &sf);

    Also, fields of statfs struct are not strings, so must not be output with %s.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •