第十二周

 

本周作业头: 

这个作业属于哪个课程C语言程序设计语言Ⅱ
这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/computer-scienceclass4-2018/homework/3236
我在这个课程的目标 指针进阶
这个作业在那个具体方面帮助我实现目标 学会使用指针和结构以及链表
参考文献 c语言程序设计

基础作业

6-1 计算最长的字符串长度 (15 分)
 

本题要求实现一个函数,用于计算有n个元素的指针数组s中最长的字符串的长度。

函数接口定义:

int max_len( char *s[], int n );

其中n个字符串存储在s[]中,函数max_len应返回其中最长字符串的长度。

 

代码

 

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define MAXN 10
#define MAXS 20

int max_len( char *s[], int n );

int main()
{
    int i, n;
    char *string[MAXN] = {NULL};

    scanf("%d", &n);
    for(i = 0; i < n; i++) {
        string[i] = (char *)malloc(sizeof(char)*MAXS);
        scanf("%s", string[i]);
    }
    printf("%d\n", max_len(string, n));

    return 0;
}
int max_len(char *s[],int n)
{
    int i;
    int max=0;
    for(i=0;i<n;i++){
        if(max<strlen(s[i]))
) } return max; }

 

 

截图

 

流程图

问题

使用strlen函数时里面数组没有加i;

解决

加上i就是


感想

这周没有好好学习。。。。。。。。

 

 

 

 

 
posted @ 2019-05-17 22:34  林衍  阅读(131)  评论(1编辑  收藏  举报