⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ho18_2.c

📁 Software Development in C: A Practical Approach to Programming and Design 软件开发:编程与设计(C))——国外经典教材·计
💻 C
字号:
#include <stdio.h>
#include <string.h>

#define ARRAY_SIZE 30
#define CHARS_PER_STRING 40

int main()
{
	static char a2DCharArray[ARRAY_SIZE][CHARS_PER_STRING];
	char *charPointerArray[ARRAY_SIZE];
	int i,j;
	char tempChar;
	char *tempPointer = NULL;

	for (i=0,tempChar = 'A';i<ARRAY_SIZE;i++)
	{
		for (j=0;j<CHARS_PER_STRING-1;j++)
		{
			if (tempChar > 'z')
			{
				tempChar = 'A';
			}

			a2DCharArray[i][j] = tempChar++;
		}
		a2DCharArray[i][CHARS_PER_STRING-1] = '\0';
	}

	for (i=0;i<ARRAY_SIZE;i++)
	{
		charPointerArray[i] = a2DCharArray[i];
	}

    printf("\nThe unsorted array...\n");
	for (i=0;i<ARRAY_SIZE;i++)
	{
		printf("%s\n",charPointerArray[i]);
	}

	for (i=1;i<ARRAY_SIZE;i++)
	{
		for (j=0;j<i;j++)
		{
			if (strcmp(charPointerArray[i],
					   charPointerArray[j]) < 0)
			{
				tempPointer = charPointerArray[i];
				charPointerArray[i] = charPointerArray[j];
				charPointerArray[j] = tempPointer;
			}
		}
	}

    printf("\nThe sorted array...\n");
	for (i=0;i<ARRAY_SIZE;i++)
	{
		printf("%s\n",charPointerArray[i]);
	}

	return (0);
}

⌨️ 快捷键说明

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