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

Help me doing this in C programming: (Please look at the requirment carefully be

ID: 3597610 • Letter: H

Question

Help me doing this in C programming: (Please look at the requirment carefully bellow)

Text like this is typed by the user.

“%” is the shell prompt and not a part of your program.

Description For this assignment you will wme program called reader. c 1hat can display files and give information about their contents. Prompt the user for one of four options: n: print this nenu c: cat a text file i et infornation about a text file q: quit If the user chooses to get information or to cat a file, you will need to prompt for the filename to prompt for the Filenane If the user chooscs to gct information, the program will say how many lincs are in the file, how many non-cmpty lincs are in the file, and how many times "luc(any mix of upper and lower casc) oocurs For the following data file My dog Lucky is plucky This output would be produced: Lines: 3 Non-enpty: 2 Lucs: 2

Explanation / Answer

#include<stdio.h>
#include<conio.h>


//this function will take the filename and calculate no. of lines non
//empty lines and lucs and also print the file line by line
void catTextFile(int *l,int *n,int *lu,char *file,int ch){
FILE *fp;
fp = fopen(file,'r+');
char line[81];
int j,state = 0,state2 = 0;
printf("ininin");
//this will check the end of file
while(!feof(fp)){
  fgets(line,81,fp);
  printf("ininininside");
  //this for loop does all the work for this function
  for(j = 0;;j++){
   if(line[j] == ''){
    if(j != 0){
     *n = *n +1;
    }
   }
   if(line[j] == ' '){
    state = 0;
    if(state2 == 5){
     state2 = 0;
    }
   }
   if(line[j] != ' '){
    state = 2;
   }
   if(state == 2 && line[j] != ' '){
    char ch = line[j];
    switch(ch){
     case 'a':
    case 'b':
    case 'c':
    case 'd':
    case 'e':
    case 'f':
    case 'g':
    case 'h':
    case 'i':
    case 'j':
    case 'k':
    case 'l':
    case 'm':
    case 'n':
    case 'o':
    case 'p':
    case 'q':
    case 'r':
    case 's':
    case 't':
    case 'u':
    case 'v':
    case 'w':
    case 'x':
    case 'y':
    case 'z':if(state2 == 3){
     *lu = *lu + 1;state2 = 5;
    }    state2 = 4;break;
    case 'A':
    case 'B':
    case 'C':
    case 'D':
    case 'E':
    case 'F':
    case 'G':
    case 'H':
    case 'I':
    case 'J':
    case 'K':
    case 'L':
    case 'M':
    case 'N':
    case 'O':
    case 'P':
    case 'Q':
    case 'R':
    case 'S':
    case 'T':
    case 'U':
    case 'V':
    case 'W':
    case 'X':
    case 'Y':
    case 'Z':if(state2 == 4){
     *lu = *lu + 1;state = 5;
    }state2 = 3;break;
    }
   }
  }
  if(ch != 1)
  printf("%s",line);
  *l = *l + 1;
}
}
//this will take input from the user and will put it into the filename
int takeInput(char *file){
printf(" FILENAME : ");
scanf("%s",file);
int i;
for(i = 0;;i++){
  if(file[i] == '')
  {
         //this will check .txt format
   if(file[i-1] == 't' && file[i-2] == 'x' && file[i-3] == 't' && file[i-4] == '.'){
    return 0;
   }
   else{
    return 1;
   }
  }
}
}
//this function will print the information of the text file
void printInfo(int l,int n,int lu){
printf("Lines : %d Non-Empty : %d Lucs : %d",l,n,lu);
}
//starting of main
int main(){
//variable to track information
int lines,non_empty,lucs,c;
char filename[51];
char choice;
start:
//clrscr();
//menu printing
printf(" m : print this menu : ");
printf("c : cat a text file ");
printf("i : get information about a file ");
printf("q : quit ");
printf(" Enter Your Choice ... ");
scanf("%c",&choice);
//making choice to go to the right function
switch(choice){
  case 'm':goto start;
  case 'c':
    c = takeInput(&filename);
    printf("%s",&filename);
         if(c){
   printf("%s doesn't end with .txt");
   getch();
   goto start;
  }
  catTextFile(&lines,&non_empty,&lucs,&filename,0);goto start;
  case 'i':
   c = takeInput(&filename);
    printf("%s",&filename);
         if(c){
   printf("%s doesn't end with .txt");
   getch();
   goto start;
  }
  catTextFile(&lines,&non_empty,&lucs,&filename,1);
  printInfo(lines,non_empty,lucs);goto start;
  case 'q':goto end;
  default:goto start;
}


end:
return 0;
}