Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cursor = head;
- fscanf(h,"%d",&q);
- for(i = 0 ; i <= q; i ++)
- {
- fgets(buff,32,h);
- buff[strlen(buff)] = '\0';
- if(strstr(buff,"backspace"))
- {
- backspace(&head,pos);
- pos = pos -1;
- }
- else if (strstr(buff,"move") != NULL)
- {
- n = atoi(buff+5);
- for(j = 0; j < pos ; j++)
- {
- if(cursor->next == NULL)
- continue;
- cursor = cursor->next;
- }
- if(n>0)
- for(j = 1; j < n; j ++)
- {
- if(cursor->next == NULL)
- break;
- cursor = cursor->next;
- }
- else if(n<0)
- for(j = 1 ; j <n ; j ++)
- {
- if(cursor->prev == head)
- break;
- cursor = cursor->next;
- }
- else continue;
- pos = pos + atoi(buff +5);
- }
- else if(strstr(buff,"copy") != NULL)
- {
- len = atoi(buff + 5);
- copy(&head, len, pos, &w);
- }
- else if(strstr(buff,"insert") != NULL)
- {
- len = strlen(buff+7);
- strcpy(string,(buff+7));
- for(i = 0; i < (strlen(string)-1) ; i++)
- {
- insert_node(&head,pos,string[i]);
- pos = pos + 1;
- }
- }
- else if(strstr(buff,"delete") != NULL)
- {
- n = atoi(buff+7);
- for(i = 0; i < n; i++)
- {
- del(&head, pos);
- pos = pos - 1;
- }
- }
- else if(strstr(buff,"paste") != NULL)
- {
- len = strlen(buff+6);
- for(i = 0; i <(strlen(w)-1); i++)
- {
- insert_node(&head,pos,w[i]);
- }
- pos = pos + (strlen(w)-1);
- }
- else if(strstr(buff,"undo") != NULL)
- printf("UNdo");
- }
- fclose(h);
- x = head;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement