Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //count.cpp: Lauri K. Friberg 2019
- //This neat counter was programmed by me, Lauri K. Friberg on the 12th of September 2019. It is in the C++ programming
- //language. You may use this program as you wish, it is Public Domain. The program starts with the number 0 and continues
- //counting towards infinity in an infinite while(1) { ... } loop. It can be aborted with Ctrl+C (^C) or Ctrl+Z (in Linux, Unix,
- //BSD, POSIX, ^Z) or with whatever means, like using the kill command in a terminal or the xkill command in the windowing mode
- //When the program is called, if there is an argument "-h" or "--help" in the call to execute the program (usually done in the
- //command line interface it shows the text "Press Ctrl+C to abort the counter and exit the program." and exits with the error
- //code 1. If there are no arguments, the program acts as a positive integer counter starting from 0 and approaching infinity.
- #include <iostream>
- #include <cstring>
- using namespace std;
- int main(int argc, char **argv)
- {
- int n=0;
- //char dummy_argument;
- //cout << argc << "\n";
- //cin >> dummy_argument;
- if (argc>1)
- {
- if (strcmp(argv[1],"--help"))
- { cout << "Press Ctrl+C to abort the counter and exit the program.\n"; return(1); }
- else if (strcmp(argv[1],"-h"))
- { cout << "Press Ctrl+C to abort the counter and exit the program.\n"; return(1); }
- }
- if (argc==1) { while(1) { cout << n << " "; n++; } }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment