Question: Explain each line of code. #include #include int main(int argc, char *argv[]) { int ch, prev, row, col; prev = EOF; FILE *fp; int y,

Explain each line of code.

#include

#include

int main(int argc, char *argv[])

{

int ch, prev, row, col;

prev = EOF;

FILE *fp;

int y, x;

if(argc != 2)

{

printf("Usage: %s ", argv[0]);

exit(1);

}

fp = fopen(argv[1], "r");

if(fp == NULL)

{

perror("Cannot open input file");

exit(1);

}

initscr();

getmaxyx(stdscr, row, col);

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

getyx(stdscr, y, x);

if(y == (row - 1))

{

printw("<-Press Any Key->");

getch();

clear(); /* clear the screen */

move(0, 0); /* start at the beginning of the screen */

}

if(prev == '/' && ch == '*') /* If it is / and * then only

* switch bold on */

{

attron(A_BOLD);

getyx(stdscr, y, x);

move(y, x - 1);

printw("%c%c", '/', ch);

}

else

printw("%c", ch);

refresh();

if(prev == '*' && ch == '/')

attroff(A_BOLD);

prev = ch;

}

endwin(); /* End curses mode */

fclose(fp);

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!