23. Write a program to read the contents from the file“sample.txt”. Store all the characters from “sample.txt”into the file “character.txt” & store all digits into the file “digit.txt “.


#include<iostream.h>
#include<stdio.h>
#include<string.h>
#include<fstream.h>
#include<conio.h>
void main()
{
char ch[20];
int n[5];
fstream f,f1,f2;
clrscr();
f.open(“sample.txt”,ios::in|ios::out);
f1.open(“chracter.txt”,ios::in|ios::out);
f2.open(“digit.txt”,ios::in|ios::out);
cout<<“Enter the data in file: \n”;
for(int i=0;i<5;i++)
{
gets(ch);
f>>ch;
cin>>n[i];
f>>n[i];
}
int len=strlen(ch);
for(i=0;i<5;i++)
{
for(int j=0;j<len;j++)
{
f>>ch[j];
f>>n[i];
}
}

while(f)
{
for(int j=0;j<len;j++)
{
f<<ch[j];
if(ch[j]>=48&&ch[j]<=57)
{
f1<<ch[j];
}
else
{
f2<<ch[j];
}
}
}
for(int j=0;j<len;j++)
{
f1>>ch[j];
cout<<“\nChracter are: “<<ch[j];
f2>>ch[j];
cout<<“\nDigit are: “<<ch[j];
}
f.close();
f1.close();
f2.close();
getch();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s