📄 editv1.c
字号:
//---------------------------------------------------------
/*
File Name: EditV1.C
Remarks: This is the first version of what will become
a text editor.
*/
//---------------------------------------------------------
// Include Files
//---------------------------------------------------------
#include <stdio.h>
// End Include Files---------------------------------------
//---------------------------------------------------------
// Constants
//---------------------------------------------------------
const int MAX_BUFFER_ROWS = 100;
const int MAX_BUFFER_COLS = 60;
const int DISPLAY_AREA_SIZE = 20;
const int SCREEN_SIZE = 25;
// End Constants-------------------------------------------
int main()
{
char textBuffer[MAX_BUFFER_ROWS][MAX_BUFFER_COLS];
int i,j;
char tempChar;
int top;
// Fill the buffer with characters.
// For each row...
for (i=0,tempChar=' ';i<MAX_BUFFER_ROWS;i++)
{
// For each column...
for (j=0;j<MAX_BUFFER_COLS-1;j++)
{
// Store a character in the buffer.
textBuffer[i][j]=tempChar++;
// If tempChar was incremented past z...
if (tempChar>'z')
{
// Reset tempChar to space.
tempChar=' ';
}
}
textBuffer[i][MAX_BUFFER_COLS-1]='\0';
}
// While the user doesn't what to quit...
top=0;
for (tempChar=' ';
(tempChar!='q') && (tempChar!='Q');
scanf("%c",&tempChar))
{
// Scroll the screen up or down based on user input.
switch (tempChar)
{
case 'U':
case 'u':
top -= DISPLAY_AREA_SIZE-1;
break;
case 'D':
case 'd':
top += DISPLAY_AREA_SIZE-1;
break;
}
/* If the index of the first line of text to be
displayed is now outside the boundaries of the
array, adjust it so that it is inside. */
if (top<0)
{
top=0;
}
else if (top >= MAX_BUFFER_ROWS)
{
top=MAX_BUFFER_ROWS-DISPLAY_AREA_SIZE;
}
// Clear the screen.
for (i=0;i<SCREEN_SIZE;i++) // For each row...
{
// Print an endline.
printf("\n");
}
// For each row of text...
for (i=top,j=0;
(i < top+DISPLAY_AREA_SIZE) &&
(i < MAX_BUFFER_ROWS);
i++,j++)
{
printf("%s\n",textBuffer[i]);
}
// Display a status line.
if (top==0)
{
printf("\nBeginning of buffer\n");
}
else if (top+DISPLAY_AREA_SIZE>=MAX_BUFFER_ROWS)
{
printf("\nEnd of buffer\n");
}
else
{
printf("\n\n");
}
// Prompt the user for a command.
printf("COMMAND:");
}
return (0);
}
//-------------------end EditV1.C--------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -