字符串排序

错误如下:

#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include<string.h>
#define NAME_LEM 10

int main()
{
	int i = 0, j = 0;

	int num = 0;
	scanf("%d", &num);

	
	char (*name)[NAME_LEM];
	name = (char (*)[NAME_LEM])malloc(sizeof(char*) * num );
	//name = new char[num][NAME_LEM];
	//printf("sizeof(a) = %d\n",sizeof(name[num - 1]));

	for(i = 0; i < num; i++)
	{
		gets(name[i]);
		//puts(name[i]);
	}

	char temp[NAME_LEM];
	for(i = 0; i < num - 1; i++)
	{
		for(j = i; j < num; j++)
		{
			if( strcmp(name[i], name[j]) == 1 )
			{
				strcpy(temp, name[i]);
				strcpy(name[i], name[j]);
				strcpy(name[i], temp);
			}
		}
		
	}

	for(i = 0 ; i < num; i++)
		free(name[i]);

	return 0;

}

点赞