C/C++ 查找字符串数组最小值:代码示例与解析
#include <stdio.h> #include <string.h>
void find(char *str[], int n, int *p) { int i, minIndex = 0; for(i = 1; i < n; i++) { if(strcmp(str[i], str[minIndex]) < 0) { minIndex = i; } } *p = minIndex; }
int main() { char *str[100]; int n = 0, i, minIndex; while(scanf("%s", str[n]) != EOF) { n++; } find(str, n, &minIndex); printf("%s", str[minIndex]); return 0; }
原文地址: https://www.cveoy.top/t/topic/ojJr 著作权归作者所有。请勿转载和采集!