LauriFriberg

count.cpp: counts 0-->infinity, positive integers

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