Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

arr_del_test

By: a guest on Feb 12th, 2014  |  syntax: None  |  size: 0.79 KB  |  views: 33  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ncurses.h>
  4.  
  5.  
  6. void arr_del(void);
  7. void arr_push(char);
  8.  
  9. char arr[100];
  10.  
  11.  
  12. int main()
  13. {
  14.     initscr();
  15.  
  16.     int row, col;
  17.     getmaxyx(stdscr, row, col);
  18.  
  19.     char ch;
  20.  
  21.     arr[0] = '\0';
  22.  
  23.     while(1) {
  24.         ch = getch();
  25.         if (ch == KEY_BACKSPACE)
  26.             arr_del();
  27.         else
  28.             arr_push(ch);
  29.         mvprintw(row/2-1, col/2, "%c", arr[strlen(arr)-1]);
  30.         mvprintw(row/2, (col - strlen(arr))/2, "%s", arr);
  31.         mvprintw(row/2+1, col/2, "%d", strlen(arr));
  32.         refresh();
  33.     }
  34.  
  35.     return 0;
  36. }
  37.  
  38. void arr_del(void) {
  39.     //int len = strlen(arr);
  40.     arr[strlen(arr)-1] = '\0';
  41. }
  42.  
  43. void arr_push(char ch) {
  44.     int len = strlen(arr);
  45.     arr[len] = ch;
  46.     arr[len+1] = '\0';
  47. }
clone this paste RAW Paste Data