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

I want the same below program but it should ignore c style comments while counti

ID: 3707472 • Letter: I

Question

I want the same below program but it should ignore c style comments while counting Answer 1 of 1 Done Solution: Note: The implementation is given in C++. code: include #include int eno-0, wno-0, 1no 0 counts of characters, words and lines character [a-zA-2) digit [0-91 word (characterl digit)+ line n (1?ne} { eno++; ino++; } (word) wno*i cnostrlen(yytext): enote int main(void) yylex) printf("Number of characters: %d: ., cno); printf("Number of words: printf("Number of lines return 0 dwno) din.Ino)

Explanation / Answer

The file pointer will read the data from textfile where we will have our C++ code. Now the Filepoiner will stop reading when we go to /* and start reading after */ . This is code in C

#include <stdio.h>

int main()

{

FILE *fp;

char filename[100];

char ch;

int linecount, wordcount, charcount;

linecount = 0;

wordcount = 0;

charcount = 0;

printf("Enter a filename :");

gets(filename);

  

  

fp = fopen(filename,"r");

int Commetstat=0;

int readlineac=0;

int rcommetstat=0;

if ( fp )

{

while ((ch=getc(fp)) != EOF) {

if(ch=='/') {Commetstat=1}

if(ch=='*' && Commetstat==1){

readlineac=1;

Commetstat=0;

}

  

if(ch=='*' && Commetstat==0)

{

rcommetstat=0;

}

if(rcommetstat==0 && ch=='/')

{

readlineac=0;

}

if(readlineac==0)

{

if (ch != ' ' && ch != ' ') { ++charcount; }

if (ch == ' ' || ch == ' ') { ++wordcount; }

if (ch == ' ') { ++linecount; }

}

}

}

if (charcount > 0) {

++linecount;

++wordcount;

}

}

else

{

printf("Failed to open the file ");

}

printf("Lines : %d ", linecount);

printf("Words : %d ", wordcount);

printf("Characters : %d ", charcount);

getchar();

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