Welcome to the Linux Foundation Forum!

LFEL1002 More Complex Syntax/Complex Syntax/File I/O and Stdout

The explanation says: "We read each line from the input file, prepend it with a line number, and then write it to both the standard output (stdout) and the output file." That is not really the case.

Instead, we:

  • read each line from the input file
  • parse it: convert a line of text to a number and proceed OR terminate the program (panic) with an error if we can't parse the line
  • multiply the number (we parsed previously) by 2
  • write the input number and the result to stdout and the output file

By the way. Each iteration we create the output.txt file anew. When the program finishes, output.txt will contain only the last parsed line (multiplied by 2). It may or may not be a logical error.

Categories

Upcoming Training