Thursday, 4 May 2017

AIM: Define an array which stores arr[]={11,22,33,44,55,66,77,88,99}. Write a program to illustrate the use of command line arguments that supplies the file name called ODD & EVEN to the program. Using command line arguments the odd numbers’ are stored into the ODD file & even numbers’ are stored into the EVEN file. Finally display the contents from both the files.


  
CODING:
#include<fstream.h>
#include<conio.h>
#include<iomanip.h>
#include<process.h>
 main(int argc,char *argv[])
{
int arr[9]={11,22,33,44,55,66,77,88,99};
if(argc!=3)
{
cout<<"parameter is not match:";
exit(1);
}
ofstream f1,f2;
f1.open(argv[1]);
if(f1.fail())
{
cout<<"error in opening file";
exit(1);
}
for(int i=0;i<=9;i++)
{
if(arr[i]%2==0)
{
f1<<arr[i];
}
f1.close();
f2.close();
ifstream fin;
char ch;
for(i=0;i<=argc;i++)
{
fin.open(argv[i]);
cout<<"content of file are";
do
{
fin.get(ch);
}
while(fin.eof());
cout<<"\n";
}
fin.close();
}
if(!argc==3)
{
cout<<"array elements are"<<endl;
cin>>argc;
}
getch();
return(0);

}

No comments:

Post a Comment

About Me

Hi, I am Prof. Amol Zade, working in the field of teaching and research from last more than 10 years. My area of interests are Artificial Intelligence, Wireless Networking, Algorithms. I have 16 International paper publications along with 4 International Conference; also 3 Books published. published on Object Oriented Programming with open source approach.