苏嵌//谭晓寅//2018.7.17

 

 

 

今日学习任务

 

  1. 熟练掌握野指针及如何防止野指针;(消灭野指针)
  2. 熟练掌握多维指针的使用;(n维指针)
  3. 熟练掌握字符串的操作;(实现并使用字符串处理函数)
  4. 熟练掌握函数的声明、定义和函数调用。

今日任务完成情况

  1. 今日四项任务基本按计划完成;
  2. 今日代码量大约是200行。

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

 

  1. 段错误出现频繁;
  2. 找不到段错误出自哪里。

今日未解决问题

今日开发收获

  1. 基本掌握如何防止野指针;
  2. 基本掌握如何定义函数及调用函数。

 

自我评价

  1. 按照开发规范完成了既定任务
  2. 独立思考能力不强。

其他

 

 

 

1、输入一个字符串,计算字符串中子串出现的次数。

  1 #include <stdio.h>

  2 #include <stdlib.h>

  3 #include <string.h>

  4

  5 #define MAX_LEN sizeof(char)*50

  6

  7 int count_str()

  8 {

  9     int i;

 10     int n;

 11     int count = 0;

 12

 13     char *ptr = (char *)malloc(MAX_LEN);

 14     char *str = (char *)malloc(MAX_LEN);

 15     char *p_temp = ptr;

 16     char *s_temp = str;

 17

 18     if(ptr == NULL || str == NULL)

 19     {

 20         printf("malloc error\n");

 21         exit(1);

 22     }

 23

 24     memset(ptr,0,MAX_LEN);

 25     memset(str,0,MAX_LEN);

 26

 27     printf("Please input string:\n");

 28     scanf("%s",ptr);

 29     printf("Please input substring:\n");

 30     scanf("%s",str);

31

 32     n = strlen(str);

 33

 34     while(*p_temp != 0)

 35     {

 36         if(strncmp(p_temp, s_temp, n) == 0)

 37         {

 38            count ++;

 39            p_temp = p_temp + n;

 40         }

 41         p_temp ++;

 42     }

 43

 44     free(ptr);

 45     free(str);

 46

 47     ptr = NULL;

 48     str = NULL;

 49

 50     return count;

 51 }

 52

 53 int main()

 54 {

 55     int result;

 56

 57     result = count_str();

 58

 59     printf("result = %d\n",result);

 60

61     return 0;

 62 }

运行结果:

Please input string:

123jkkasjdffiaweowo3123jka123klafjk123

Please input substring:

123

result = 4

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值