index | submit | rank | book

run-count – Counting program runs

Write a program that prints how many times it has been run by means of a runcount.txt file like so:

$ ./run-count
run #1
$ ./run-count
run #2
$ ./run-count
run #3

If it is the first time your program is running in the working directory, a runcount.txt file should be created with the number 1 and your program should print run #1. Each time your program is run, the number n in the runcount.txt file should be incremented and your program should print run #n.

Run count

The number should be stored in the file in a proper line, i.e., followed by a line break.

Scoring

Hints

To avoid issues with seeking the correct position on the runcount.txt file, you can open and close the file twice: first for getting the current run count; then for writing the updated run count. This way you will not have to worry about positioning the reading or writing pointers on the file as whenever you reopen a file the pointer is positioned at the beginning.

Do not forget to follow the number in runcount.txt by a line break.

try first: file-write file-read

try next: hello-cmd erro

index | submit | rank | book

Copyright © 2020-2023 Rudy Matela
All rights reserved