Need to make program for the language C: Output: Generate an output file (output
ID: 3683884 • Letter: N
Question
Need to make program for the language C:
Output: Generate an output file (output.dat) that contains a converted list of dates in day, abbreviated month & year format (1 JAN 1900), followed by the original list of dates in month/day/year format (1/1/1900). This output file will be the result of appending the input file (dates.dat), which is accessed by the first program, with the result output file (output.dat), generated by the second program.
Input: Accept input for the first program via the command-line arguments. Input will be the number of valid entries to be redirected from the dates input file (dates.dat). A zero indicates to input all entries from the dates input file. Your program should validate (day, month & year - see page 111 for validation ideas) and skip corrupt dates in the dates.dat file. This validated input will then be piped out to the second program.
The second program will accept these validated dates in the month/day/year format and convert each of them to the day, abbreviated month & year format — both exhibited above. The abbreviated month should consist of the first three letters of the month, capitalized. These converted results will be redirected to the output file (output.dat), followed by a copy of the original (dates.dat) data.
Requirements: Implement a pair of programs that will interface and exchange data — in this case, a list of dates. You may use any material discussed in the first seven chapters. Minimum of two source code files — one for each main() — for the separate programs. You may develop additional source code or headers files, if you wish. You should develop your own dates.dat for testing; however, I will likely use my own file for my execution. Command line could look something like:
$ ./program1 < dates.dat 0 | ./program2 > output.dat
Explanation / Answer
//#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <conio.h>
int main()
{
FILE *fp;
char ch;
int i;
char date1[10]; // 12/11/1997
char dd[2], mm[2], yr[4];
char month[20];
//int day, month, year;
fp = fopen("E:/Files/dates.txt", "r");
while(1)
{
ch=fgetc(fp);
if( feof(fp) ) { break ; }
putchar(ch);
//getchar();
} // end while
fscanf(fp, "%s", date1);
// strncpy(dd,date1,2);
dd = substr(date1,0, 2);
mm = substr(date1,3,2);
yr = substr(date,6,4);
// 12/11/1997
switch (mm) {
case "01":
strcpy(month," January");
break;
case "02":
strcpy(month,"Febrauary ");
break;
case "03":
strcpy(month," March");
break;
case "04":
strcpy(month," April");
break;
case "05":
strcpy(month," May");
break;
case "06":
strcpy(month," June");
break;
case "07":
strcpy(month," July");
break;
case "08":
strcpy(month," August");
break;
case "09":
strcpy(month," September");
break;
case "10":
strcpy(month," October");
break;
case "11":
strcpy(month," November");
break;
case "12":
strcpy(month," December");
break;
} // end switch
printf ("%s %s", date1, dd);
FILE *op;
op = fopen("E:/Files/dateOp.txt");
fprintf(op, "%s %s %s", dd month yr);
fclose(fp);
fclose(op);
return 0; // exit
} // end of main()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.