In: Computer Science
IN C LANGUAGE
This program takes two command line arguments:
Your program will create two files:
Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change.
If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions.
Thank You!
===========================================================================
#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
int main(int argc, char *argv[]){
// convert command line number to integer
int threshold = atoi(argv[2]);
char even_filename[] = "even.txt";
char odd_filename[] = "odd.txt";
FILE* infile = fopen(argv[1],"r");
FILE* evenfile = fopen(even_filename,"w");
FILE* oddfile = fopen(odd_filename,"w");
if(infile==NULL || evenfile==NULL ||
oddfile==NULL){
printf("Error: Reading Writing to
files.");
return 1;
}
int val;
while(fscanf(infile,"%d",&val)!=EOF){
if(val%2==0 && val >
threshold){
fprintf(evenfile,"%d\n", val);
}
else if(val%2==1 &&
val>threshold){
fprintf(oddfile,"%d\n", val);
}
}
// close the file handlers
fclose(infile);
fclose(evenfile);
fclose(oddfile);
printf("Files generated successfully.");
}
==================================================================