ho10_2.c

来自「Software Development in C: A Practical A」· C语言 代码 · 共 58 行

C
58
字号
#include <stdio.h>

int main()
{
	int i;
	int j;
	char tempChar;
	char anArray[100];
	int top;

	// Fill the array.
	for (i=0,tempChar=' ';i<100;i++)
	{
		anArray[i]=tempChar++;
  	}

	for (top=0,tempChar=' ';
		 (tempChar!='q') && (tempChar!='Q');
		 scanf("%c",&tempChar))
	{
		switch (tempChar)
		{
			case 'U':
			case 'u':
				top -= 20-1;
			break;

			case 'D':
			case 'd':
				top += 20-1;
			break;
		}

		if (top<0)
		{
			top=0;
		}
		else if (top >= 100)
		{
			top=100-20;
		}

		if (tempChar != '\n')
		{
			for (i=top,j=0;
				 (i < top+20) && (i < 100);
				 i++,j++)
			{
				printf("Display Line %d",j);
				printf(":  Array element %d: %c\n",
					   i,
					   anArray[i]);
			}
			printf("\nCOMMAND:");
		}
	}
	return (0);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?