Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Copyright (c) 2013 by Vimja
- // This code is released under the terms
- // of the WTFPL (What the Fuck Pulic License) version 2.0
- // http://sam.zoy.org/wtfpl/
- #include <stdio.h>
- #include <stdlib.h>
- #include <curses.h>
- #include <string.h>
- int main()
- {
- // Huge array to hold 1K of pi numbers
- char pi[] = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989";
- // count the numbers
- int i;
- // read in the character
- int c;
- // wanna retry?
- int retry;
- // cursor position
- int cursorX = 5;
- int cursorY = 5;
- // initialize ncurses stuff
- WINDOW *mywindow;
- mywindow = initscr();
- nodelay(mywindow, FALSE);
- do {
- i = 0;
- retry = 'a';
- // prepare ncurses window
- erase();
- printw("pi:\n");
- refresh();
- flushinp();
- // read the input and compare
- do {
- c = getch();
- i++;
- } while ((int)pi[i-1] == c && i-1 < strlen(pi));
- // retrieve cursor position:
- cursorY = getcury(mywindow);
- cursorX = getcurx(mywindow);
- // delete the wrong character
- move(cursorY, cursorX-1);
- delch();
- // now redraw the last (wrong) character, but underline it
- attron(A_UNDERLINE);
- printw("%c", (char)c);
- refresh();
- attroff(A_UNDERLINE);
- // print information about the users score
- printw("\nYou got %d digits of pi right \n", i-1);
- // Teach the user some more numbers
- if(i-1 < (int)strlen(pi)-5)
- printw("Here are the next 5 chars of pi: %c%c%c%c%c \n", pi[i-1], pi[i], pi[i+1], pi[i+2], pi[i+3]);
- else if (i-1 < (int)strlen(pi))
- printw("Here are all the remaining numbers known to this application: %s \n", &pi[i-1]);
- else
- printw("You beat the shit out of this application which has totally ran out of numbers! \n");
- // Ask the user if they want to retry
- do {
- printw("Hit 'r' to retry or 'q' to abort\n");
- refresh();
- flushinp();
- retry = getch();
- } while (retry != 'r' && retry != 'q');
- } while (retry == 'r');
- // kill the ncurses window
- endwin();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment