fortran program – File I/O – Identify Long Words PURPOSE: The purpose of this ex
ID: 3684363 • Letter: F
Question
fortran program – File I/O – Identify Long Words
PURPOSE: The purpose of this exercise is to provide a program that identifies long words in an input file and stores them in an output file.
This program shall obtain and validate input and output file names specified by the program user.
Assume that input lines from the source file may be truncated when greater than 250 characters in length. Words in the input file at least 6 characters in length are to be written as-is, one per line, to the output file. Minimum word length should be a parameterized constant in the program. A “word” must be considered as any sequence of characters consisting of only upper case letters, lower case letters, apostrophe, (’), or hyphen (-).
Explanation / Answer
Solution: Program as shown in below
#include<stdio.h>
#include<conio.h>
main ()
{
FILE *fptr;
int nl=0,nw=0,nc=250; char ch =6;
clrscr();
fptr=fopen(“input.c”,”r”); if (fptr!=NULL)
{
while (!foef(fptr))
{
ch=getc (fptr);
if (ch==’ ‘||ch==’ ’)
nw++;
else if(ch==’ ’)
nl++;
else nc++;
}
fclose (fptr);
fptr=fopen (“output.c” , ”w”);
fprintf (fptr,”number of lines =%d ” , nl);
fprintf (fptr,”number of words =%d ” , nw);
fprintf (fptr,”number of characters =%d ” , nc);
}
else
printf(“the input file does not exist ”);
getch();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.