1
#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值提供最小字符串。指針指針
我的錯誤消息指出我傳遞了不兼容的指針類型來處理字符串。當我畫出指針時,我感覺好像我不是。幫幫我?