Tuesday, October 4, 2011

Data Structure Lab Programs -save data on disk and read data from disk .

 

Practical # 10

 

 

/* To save data on disk and read data from disk */

 

#include<fstream.h>

#include<stdio.h>

void write()

{

    ofstream f("TEXT.txt");

    char str[20];

    if(!f)

    {

    printf("\n Cannot open the file");

    return;

    }

    printf("\nEnter your name\n");

    gets(str);

    f<<str;

    f.close();

}

void read()

{

ifstream f("TEXT.txt");

if(!f)

{

printf("\n Cannot open this file");

return;

}

char str[20];

while(!f.eof())

{

  f>>str;

  puts(str);

}

f.close();

}

void main()

{

printf("\n WRITING………...");

write();

printf("\n READING………...");

read();

}

 

 

Output:-

 

 

 

WRITING………...

Enter your name

Sonu

 

 

READING………...

Sonu

 

 

No comments :

Post a Comment