Monday, 7 July 2014

-------------------------------
OSD 1
--------------------------------

#include<iostream>
#include<fstream>
#include<sys/stat.h>
using namespace std;

class inode
{
private:
    char filename[20];
    struct stat buf;
public:
    void get_filename();
    void create_file();
    void display_data();
};

void inode::get_filename()
{
    cout<<"enter the name of file";
    cin>>filename;
}

void inode::create_file()
{
    ofstream write(filename);
    if(write.is_open())
    {
        cout<<"\n\n file "<<filename<<" has been created successfully";
        write.close();
    }
    else
    {
        cout<<"\n\n file can not be created"<<filename;
    }
}
void inode::display_data()
{
    cout<<"\n\n FILE DETAILS";
    cout<<"\n FILENAME \t"<<filename;
    stat(filename,&buf);
    cout<<"\n INODE NUMBER \t"<<buf.st_ino;
    cout<<"\n SIZE \t"<<buf.st_size<<"\n";
    cout<<"\n -------------------------";
}

int main()
{
    inode i;
    i.get_filename();
    i.create_file();
    i.display_data();
    return 0;
}

/*
------------
output
------------

enter the name of file
ashwini


 file ashwini has been created successfully

 FILE DETAILS
 FILENAME     ashwini
 INODE NUMBER     1972343
 SIZE     0

 -------------------------
*/

No comments:

Post a Comment