#include <stdio.h>
#include <string.h>
void F1(void *comp, void *record){
int complen = strlen((char *)comp), recordlen = *(int *)record;
*(int *)record = complen>recordlen ? complen : recordlen;
}
void F2(void *comp, void *ans){
if(!*(char **)ans)
*(char **)ans = (char *)comp;
else if(strcmp((char *)comp, *(char **)ans) < 0)
*(char **)ans = (char *)comp;
}
void ProcessStrings(char ***vals, void* (*fp)(char *, void *), void *champ){
char **copy = *vals;
while(*copy){
fp(*copy++, champ);
}
}
int main() {
char *strings1[][100] = {{"beta", "alpha", "gamma", "delta", NULL}, {"Johnson", "Smith", "Smithson", "Zimmerman", "Jones", NULL}, {"Mary", "Bill", "Bob", "Zoe", "Annabelle", "Bobby", "Anna", NULL}};
int maxLen = 0;
char *minString = NULL;
ProcessStrings(strings1, F1, &maxLen);
ProcessStrings(strings1, F2, &minString);
printf("Strings1: Max length is %d and min is %s\n", maxLen, minString);
}
快速背景...函数 F1 将字符串列表的最大长度提供给它的第二个参数。F2 提供 ASCII 值方面的最小字符串。
我的错误消息指出我正在传递一个不兼容的指针类型来处理字符串。当我画出指针时,我感觉好像我不是。帮助?