C语言字符串最小值查找函数实现
#include <stdio.h> #include <string.h>
void find(char *name[], int n, int *p);
int main() { char str[100][7]; int i = 0; while (1) { scanf("%s", str[i]); if (strcmp(str[i], '####') == 0) { break; } i++; } int min_index; find(str, i, &min_index); printf("%s\n", str[min_index]); return 0; }
void find(char *name[], int n, int *p) { int i, min_index = 0; for (i = 1; i < n; i++) { if (strcmp(name[i], name[min_index]) < 0) { min_index = i; } } *p = min_index; }
原文地址: https://www.cveoy.top/t/topic/ojKY 著作权归作者所有。请勿转载和采集!