RSS

Category Archives: File Handling

PROGRAM TO PRINT THE DATA FROM A FILE THROUGH THE PRINTER

// PROGRAM TO OPEN A FILE FOR PRINTER

#include <fstream.h>
#include <conio.h>

void main()
{
clrscr();
ifstream fin(“STORY.TXT”);
char ch;
ofstream fout(“PRN”,ios::out);
while(fin.get(ch))
fout.put(ch);
getch();
}

Advertisements
 
Leave a comment

Posted by on August 17, 2015 in File Handling

 

PROGRAM TO WRITE A STRING TO A FILE CHARACTER BY CHARACTER

// THIS PROGRAM OUTPUTS A STRING TO A FILE CHARACTER BY CHARACTER

#include <fstream.h>
#include <conio.h>
#include <string.h>

void main()
{
clrscr();

char str[100];

strcpy(str,”THERE IS AN ISLAND OF OPPORTUNITIES IN THE MIDDLE OF EVERY DIFFICULTY”);

ofstream file(“TEXT.TXT”);

for(int i =0; str[i]!=”; i++)
{
file<<str[i];
}

file.close();

getch();
}

 
Leave a comment

Posted by on July 31, 2015 in File Handling

 

PROGRAM TO COUNT THE NUMBER OF UPPERCASE VOWELS PRESENT IN A FILE

// THIS PROGRAM COUNTS THE NUMBER OF UPPERCASE VOWELS PRESENT IN A FILE

#include <fstream.h>
#include <conio.h>
#include <stdio.h>
#include <process.h>

void main()
{
clrscr();
char name[20];
cout<<“Enter the name of the file to be opened\n”;
gets(name);

ifstream file(name,ios::in);
char ch;
int count = 0;

if(!file)
{
cout<<“\nFile could not be opened\n”;
exit(1);
}

while(file.eof() == 0)
{
file.get(ch);
if(file.good() == 0)
break;
if(ch == ‘A’ || ch == ‘E’ || ch == ‘I’ || ch == ‘O’ || ch == ‘U’)
count++;
}

cout<<“\nThe number of uppercase vowels are \n”<<count;
getch();
file.close();
}

 
Leave a comment

Posted by on July 31, 2015 in File Handling

 

PROGRAM TO CREATE THREE FILES FROM A FILE AND STORE DATA IN THEM ACCORDINGLY

// THIS PROGRAM CREATES THREE FILES FROM A FILE

#include <fstream.h>
#include <conio.h>
#include <stdio.h>
#include <ctype.h>

void main()
{
clrscr();
ifstream file;
char name[30];
cout<<“ENTER THE NAME OF THE FILE FROM WHICH YOU WANT TO EXTRACT\n”;
gets(name);
ofstream upper,lower,digit;
upper.open(“UPPER.TXT”);
lower.open(“LOWER.TXT”);
digit.open(“DIGIT.TXT”);
file.open(name);
char ch;

while(file.get(ch))
{
if(file.good() == 0)
break;

if(islower(ch))
{
if(ch == ‘a’ || ch == ‘e’ || ch == ‘i’ || ch == ‘o’ || ch == ‘u’)
lower<<ch;
}
else if(isupper(ch))
{
if(ch == ‘A’ || ch == ‘E’ || ch == ‘O’ || ch == ‘U’ || ch == ‘I’)
upper<<ch;
}
else
{
if(isdigit(ch))
digit<<ch;
}
}

cout<<“\nDATA SUCCESSFULLY WRITTEN\n”;
getch();
}

 
Leave a comment

Posted by on July 31, 2015 in File Handling

 

PROGRAM TO DISPLAY THE DATA OF A FILE IN LOWERCASE

/* THIS FUNCTION TAKES THE FILE NAME AS AN ARGUMENT AND DISPLAYS DATA
IN LOWERCASE ALPHABETS  */

#include <fstream.h>
#include <conio.h>
#include <stdio.h>
#include <ctype.h>
#include <process.h>

void displower(char []);

void main()
{
clrscr();
char name[30];
cout<<“ENTER THE NAME OF THE FILE\n”;
gets(name);
displower(name);
getch();
}

void displower(char fname[])
{
ifstream file(fname);

if(!file)
{
cout<<“\nFILE COULD NOT BE OPENED\n”;
exit(1);
}

char ch;
while(file.get(ch))
{
if(file.good() == 0)
break;
ch = tolower(ch);
cout.put(ch);
}
cout<<endl;
return;
}

 
Leave a comment

Posted by on July 31, 2015 in File Handling

 

PROGRAM TO DISPLAY THE SIZE OF A FILE IN BYTES

// THIS PROGRAM DISPLAYS THE SIZE OF A FILE IN BYTES

#include <fstream.h>
#include <conio.h>

void main()
{
clrscr();
ifstream file;
char add[20];
cout<<“ENTER THE NAME OF THE FILE WHOSE SIZE YOU WANT TO CALCULATE\n”;
cin.getline(add,20);

file.open(add);
int size = 0;

file.seekg(0,ios::end);
size = file.tellg();

cout<<“\nTHE SIZE OF THE FILE IS \n”<<size<<” bytes”;
getch();
}

 
Leave a comment

Posted by on July 31, 2015 in File Handling

 

PROGRAM TO DISPLAY THE SUM OF DIGITS PRESENT IN A TEXT FILE

//THIS PROGRAM DISPLAYS THE SUM OF DIGITS PRESENT IN A FILE

#include <fstream.h>
#include <conio.h>
#include <stdio.h>
#include <process.h>

void main()
{
clrscr();
ifstream fin;
char add[20];
int sum = 0, num;
cout<<“Enter the name of the file \n”;
gets(add);
fin.open(add,ios::in);

if(!fin)
{
cout<<“\nFile could not be opened \n”;
exit(1);
}

while(fin>>num)
{
if(fin.good() == 0)
break;
sum += num;
}

cout<<“\nThe sum of the digits is \n”<<sum;
getch();
fin.close();
}

 
Leave a comment

Posted by on July 31, 2015 in File Handling