char *name[]={"Follow me","BASIC","Great Wall","FORTRAN","Computer design"}; 在函数f1中比较字符串长度,在主函数中输出最长的字符串
时间: 2023-12-11 13:33:24 浏览: 71
以下是实现上述功能的C语言代码:
```c
#include <stdio.h>
#include <string.h>
void f1(char *name[], int len, char **max) {
int max_len = 0;
for (int i = 0; i < len; i++) {
int cur_len = strlen(name[i]);
if (cur_len > max_len) {
max_len = cur_len;
*max = name[i];
}
}
}
int main() {
char *name[] = {" me", "BASIC", "Great Wall", "FORTRAN", "Computer design"};
int len = sizeof(name) / sizeof(name[0]);
char *max = NULL;
f1(name, len, &max);
printf("The longest string is: %s\n", max);
return 0;
}
```
阅读全文