我正在尝试创建一个对字符串进行排序的函数,并且我已经创建了一个我认为应该可以工作的函数,但是 toupper()
函数似乎没有任何效果.我在这里缺少什么吗?
void selectionSort(string array[], int size) {
int startScan, minIndex;
string minValue;
for(startScan=0; startScan<(size-1); startScan++) {
minIndex = startScan;
minValue = array[startScan];
for(int index=startScan+1; index<size; index++) {
string word = array[index];
toupper(word[0]);
if(array[index] < minValue) {
minValue = array[index];
minIndex = index;
}
}
array[minIndex] = array[startScan];
array[startScan] = minValue;
}
}
最佳答案
toupper(word[0]);
此语句计算表达式 toupper(word[0])
的值,然后将结果丢弃。
将其更改为:
word[0] = toupper(word[0])
关于c++ - 使用选择排序对字符串进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35169642/