Advertisement
Guest User

arr_del_test

a guest
Feb 12th, 2014
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement