Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include "ITI.h"
- #define right 77
- #define left 75
- #define Enter 13
- #define del 83
- #define ins 82
- #define moveR 1
- #define moveL 2
- #define delete 3
- #define ent 4
- #define insert 5
- int main()
- {
- char* line = (char*)malloc(10 * sizeof(char));
- char* start, * cur, * end;
- start = cur = end = line;
- char key = ' ';
- int linesize=0;
- int command = 0;
- char* i = line;
- int replacemet = 0;
- while (1) {
- key = _getch();
- if (key == -32 || key == NULL) {
- key = _getch();
- }
- switch (key) {
- case right:
- command = moveR;
- break;
- case left:
- command = moveL;
- break;
- case del:
- command = delete;
- break;
- case ins:
- command = insert;
- break;
- case Enter:
- command = ent;
- default:
- command = 0;
- }
- switch (command)
- {
- case moveR:
- if (cur != end) {
- cur++;
- }
- break;
- case moveL:
- if (cur != start) {
- cur--;
- }
- break;
- case delete:
- if (linesize != 0) {
- for (char* y = cur; y < end - 1; y++) {
- *y = *(y + 1);
- }
- end--;
- linesize--;
- }
- break;
- case insert:
- if (replacemet == 0) {
- replacemet = 1;
- }
- else
- if (replacemet == 1) {
- replacemet == 0;
- }
- break;
- default:
- if (replacemet == 0) {
- if (linesize < 10) {
- end++;
- linesize++;
- for (char* k = end - 2; k >= cur; k--) {
- *(k + 1) = *k;
- }
- *cur = key;
- cur++;
- }
- }
- else
- if (linesize != 0) {
- *cur = key;
- }
- else
- end++;
- linesize++;
- break;
- }
- system("cls");
- for (i = line; i < end; i++)
- {
- if (i == cur)
- {
- printHighlighted(*i);
- }
- else
- {
- printf("%c", *i);
- }
- }
- if (cur == end) {
- printHighlighted(" ");
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement