Printing Lines with an Even Number of Characters from Stdin

How to print lines with an even number of characters from stdin using fgets and fputs functions?

To accomplish the task of printing lines with an even number of characters from stdin, how can you implement code in no_odd_lines.c using fgets and fputs functions?

Solution:

To print lines with an even number of characters from stdin using fgets and fputs functions, you can implement code in no_odd_lines.c. Here's an example implementation:

#include
int main() {
  char line[100];
  while (fgets(line, sizeof(line), stdin)) {
    int count = 0;
    for (int i = 0; line[i] != '\0'; i++) {
      count++;
    }
    if (count % 2 == 0) {
      fputs(line, stdout);
    }
  }
  return 0;
}

← Click through rate ctr calculation how to measure your marketing success Who is the senior petty officer in charge of a maintenance group and responsible for 3m system operation →