苏嵌 马明杰 2018.07.17

今日学习任务

1、熟练掌握野指针及如何防止野指针

2、 熟练掌握多维指针的使用

3、 熟练掌握字符串的操作;

4、 熟练掌握字符串的操作;

今日任务完成情况

1、指针的定义

2、为什么需要指针

3、指针的字节长度

4、* &运算符的作用

5、多维指针的作用

6、野指针的定义

7、避免野指针的方法

8、函数的基本语法和程序框架

今日开发中出现的问题汇总

1、出现了野指针

2、数据类型不匹配

今日未解决问题
今日开发收获

了解了指针的定义以及步长概念;

了解了指针在c语言中的作用

了解了如何避免野指针的方法

学习了函数的作用

自我评价今天主要学习了c语言中指针和函数的部分知识点;让我对c语言的了解更深入了一步;同时也做了相关的练习,但在练习中相关知识点掌握不够,依旧操作起来不熟练,,需要多加练习。
其他

程序1:

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAX_LEN sizeof (char) * 100
int main()
{
    char *ptr = (char * )malloc(MAX_LEN);
    char *temp = ptr;
    if(ptr == NULL)
    {
        printf("malloc error!\n");
    exit(1);
    }
    memset(ptr,0,MAX_LEN);
    scanf("%s",ptr);
    while(*temp != '\0')
    {
        printf("%c\n",*temp);
    temp++;
    }
    free(ptr);
    ptr = NULL;
    return 0;
}
 

程序2:

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAX_LEN sizeof (char) * 100
int main()
{
    int len = 0;
    int max = 0;
    char *ptr = (char * )malloc(MAX_LEN);
    char *temp = ptr;
    if(ptr == NULL)
    {
        printf("malloc error!\n");
    exit(1);
  
    } 
    memset(ptr,0,MAX_LEN);
    printf("请输入一个字符串:\n");
    scanf("%s",ptr);
    while(*temp != '\0')
    {
        while(*temp >= '0' && *temp <= '9')
    {
        len++;
        temp++;
    }
    if(len > max)
    {
        max = len;
    }
    len = 0;
    temp++;
    }
    printf("最长的数字串为%d\n",max);
    free(ptr);
    ptr = NULL;
    return 0;

}
 

 

 

程序3:

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAX_LEN sizeof (char) * 100
int main()
{
    int i;
    int len = 0;
    int max = 0;
    char *p = (char * )malloc(MAX_LEN);
    char *s = (char * )malloc(MAX_LEN); 
    char *temp = p;
    char *s_temp = s;
    if(p == NULL || s == NULL)
    {
        printf("malloc error!\n");
    exit(1);
  
    } 
    memset(p,0,MAX_LEN);
    memset(s,0,MAX_LEN);
    printf("请输入一个字符串:\n");
    scanf("%s",p);
    while(*temp != '\0')
    {
        while(*temp >= '0' && *temp <= '9')
    {
        len++;
        temp++;
    }
    if(len > max)
    {
        max = len;
        for(i = 0; i < len; i++)
        {
           *(s_temp + i) = *(temp - len + i);
        }
        *(s_temp + i) = '\0';
    }
    len = 0;
    temp++;
    }
    printf("最长的数字串为%d\n",max);
    free(p);
    p = NULL;
    return 0;

}
 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值