Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Modify the following program to use fgetc and fputs rather thangetchar and puts.

ID: 3615529 • Letter: M

Question

Modify the following program to use fgetc and fputs rather thangetchar and puts...the program should give the user the option toread from the standard input and write to the standard output or toread from a specified file and write to a specified file. If theuser chooses option 2, have the user enter the file names for theinput and output files.

#include <stdio.h>

int main (void){
char c;
char sentence [100];
int i = 0;
puts ("Enter a line of text:");
while ( ( c = getchar() ) != ' '){
            sentence [ i++] = c;
}
sentence [i] = '';
puts ( " The line entered was:");
puts (sentence);
return 0;
}


Explanation / Answer

please rate - thanks #include #include int main (void){ char c; char sentence [100]="stdin"; int i = 0,j; int choice; FILE *in,*out; printf("input and output using files(enter 1) or standardoutput(enter anything but 1): "); scanf("%d",&choice); while ( fgetc(stdin) != ' '); if(choice==1)     {printf("enter input file name: ");     scanf("%s",&sentence);    if(!(in=fopen(sentence,"r")))       {printf(" Error opening%s ",sentence);        getch();       return 1;      }    } else      in=stdin; if(choice==1)     {printf("enter output file name: ");       scanf("%s",&sentence);         if(!(out=fopen(sentence,"w")))         {printf(" Erroropening %s ",sentence);         getch();         return 1;         }      } else    out=stdout; if(choice!=1)      fputs ("Enter a line of text: ",out); while ( ( c = fgetc(in) ) != ' ')            sentence [ i++] = c; sentence[i]=''; if(choice!=1)      fputs ( " The line entered was:",out); for(j=0;sentence[j]!='';j++)      fputc(sentence[j],out); printf(" program complete-press any key to exit "); fclose(in); fclose(out); getch(); return 0; }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote