Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. cursor = head;
  2. fscanf(h,"%d",&q);
  3.  
  4. for(i = 0 ; i <= q; i ++)
  5. {
  6. fgets(buff,32,h);
  7. buff[strlen(buff)] = '\0';
  8. if(strstr(buff,"backspace"))
  9. {
  10.  
  11. backspace(&head,pos);
  12. pos = pos -1;
  13. }
  14. else if (strstr(buff,"move") != NULL)
  15. {
  16.  
  17. n = atoi(buff+5);
  18. for(j = 0; j < pos ; j++)
  19. {
  20. if(cursor->next == NULL)
  21. continue;
  22. cursor = cursor->next;
  23.  
  24. }
  25.  
  26. if(n>0)
  27. for(j = 1; j < n; j ++)
  28. {
  29. if(cursor->next == NULL)
  30. break;
  31. cursor = cursor->next;
  32. }
  33. else if(n<0)
  34. for(j = 1 ; j <n ; j ++)
  35. {
  36. if(cursor->prev == head)
  37. break;
  38. cursor = cursor->next;
  39.  
  40. }
  41. else continue;
  42. pos = pos + atoi(buff +5);
  43. }
  44. else if(strstr(buff,"copy") != NULL)
  45. {
  46.  
  47. len = atoi(buff + 5);
  48. copy(&head, len, pos, &w);
  49. }
  50. else if(strstr(buff,"insert") != NULL)
  51. {
  52. len = strlen(buff+7);
  53. strcpy(string,(buff+7));
  54. for(i = 0; i < (strlen(string)-1) ; i++)
  55. {
  56. insert_node(&head,pos,string[i]);
  57. pos = pos + 1;
  58. }
  59.  
  60. }
  61. else if(strstr(buff,"delete") != NULL)
  62. {
  63. n = atoi(buff+7);
  64. for(i = 0; i < n; i++)
  65. {
  66. del(&head, pos);
  67. pos = pos - 1;
  68. }
  69. }
  70. else if(strstr(buff,"paste") != NULL)
  71. {
  72. len = strlen(buff+6);
  73. for(i = 0; i <(strlen(w)-1); i++)
  74. {
  75. insert_node(&head,pos,w[i]);
  76. }
  77. pos = pos + (strlen(w)-1);
  78. }
  79. else if(strstr(buff,"undo") != NULL)
  80. printf("UNdo");
  81.  
  82. }
  83. fclose(h);
  84.  
  85. x = head;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement