试图挑选结构的数组。 结构是TextArt下面定义
typedef struct //struct that holds ASCII art
{
char artistName[80]; //name of artist
char asciiArt[20][80]; //actual ascii art line by line
int rating; //rating of art
}TextArt;
我不认为这个结构有什么关系这虽然。 我得到的编译器错误
错误:试图分配一个结构到另一个(如下图所示),当左值要求作为分配的左操作数
temp = asciiArt+pos_min;
asciiArt+pos_min = asciiArt+i; //error here
asciiArt+i = *temp; //error also here
调用函数
selectionSort(artPtr, artArrSize);
和全选择排序功能。 有什么事我不理解有关分配使用=在C中的结构? 我认为这是非此即彼我对TextArt阵列的传球在某种程度上是错误的。 请赐教谢谢。
void selectionSort(TextArt *asciiArt, int size)
{
//pos_min is short for position of min
int pos_min;
TextArt *temp;
int i=0;
int j=0;
for (i=0; i < size-1; i++)
{
pos_min = i;//set pos_min to the current index of array
for (j = i + 1; j < size; j++)
{
if ((strncmp((asciiArt+i)->artistName, (asciiArt+j)->artistName)) < 0)
{
pos_min = j; //pos_min will keep track of the index that min is in, this is needed when a swap happens
}
}
//if pos_min no longer equals i than a smaller value must have been found, so a swap must occur
if (pos_min != i)
{
printf("copying...\n");
temp = asciiArt+pos_min;
asciiArt+pos_min = asciiArt+i;
asciiArt+i = *temp;
}
}