Saturday, 23 June 2012

program -46

#include<conio.h>
#include<ctype.h>
#include<string.h>
#include<stdlib.h>
#include<iostream.h>
#include<fstream.h>
int main()
{
char ch,str[30];
int len,i;
clrscr();
fstream f1,f3,f2;
f1.open("sam.txt",ios::trunc|ios::in|ios::out);
f2.open("character.txt",ios::trunc|ios::in|ios::out);
f3.open("digit.txt",ios::trunc|ios::in|ios::out);
cout<<"enter the string which contain number also:-";
cin>>str;
len=strlen(str);
for(i=0;i<len;i++)
f1.put(str[i]) ;
f1.seekg(0);
while(f1)
{
f1.get(ch);
if(isdigit(ch)>0)
{
f3.put(ch);
}
if(isalpha(ch)>0)
{
f2.put(ch);
}
}
cout<<"\nthe number are stored in digit.txt";
cout<<"\nthe characters are stored in character.txt\n";
f1.seekg(0);
f2.seekg(0);
f3.seekg(0);
cout<<"\ncontent of file character.txt\n";
while(f2)
{
f2.get(ch);
cout<<ch;
}
cout<<"\ncontent of digit.txt\n";
while(f3)
{
f3.get(ch);
cout<<ch;
}

f1.close();
f2.close();
f3.close();
getch();
return 0;
}

No comments: