# include <stdio.h># include <string.h>void check(char *a, char *b, int(*cmp)(const char *, const char *));void main(){char s1[80], s2[80];int(*p)(const char *, const char *); /* 函數指針 */p = strcmp; /* 將函數strcmp的地址賦給函數指針p */printf("輸入兩個字符串:\n");gets(s1); /* 輸入字符串1 */gets(s2); /* 輸入字符串2 */check(s1, s2, p); /* 通過指針變量p傳遞函數strcmp的地址 */}void check(char *a, char *b, int(*cmp)(const char *, const char *)){printf("測試是否相等\n");if(!(*cmp)(a, b))printf("結果:相等\n");elseprintf("結果:不相等\n");}就想問:*cmp不是指向strcmp函數么?那么if(!(*cmp)(a, b))應該表示if((*cmp)(a, b)==0)是么?
- 2 回答
- 0 關注
- 104 瀏覽
添加回答
舉報
0/150
提交
取消