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;
}

← The importance of agent policy in managing network systems How to properly use the suid flag in linux →