|
|
今日学习任务 | 1、 熟练掌握野指针及如何防止野指针;(消灭野指针)
|
今日任务完成情况
| 完成老师bu'z布置任务 完成老师布置作业 |
开发中出现的问题汇总
| 没有给指针分配空间,造成段错误 较少使用函数
|
今日未解决问题
| 无 |
今日开发收获 | 学会了代码的编写规范,为以后的工作打下了良好的基础 学会了函数在定义,调用,声明时候编写的规范。 |
自我评价
| 今天学习过程中,了解许多关于指针的知识,知道了什么叫野指针,如何减少运用指针的错误。 |
| 无 |
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 #define MAX_LEN sizeof(char) * 100
6 int main()
7 {
8 char *ptr = (char *)malloc(MAX_LEN);
9 char *s = (char *)malloc(MAX_LEN);
10
11 char *p_temp=ptr;
12 char *s_temp=s;
13
14 int i;
15 int max = 0;
16 int count = 0;
17
18 printf("please input string:\n");
19 scanf("%s",ptr);
20 p_temp = ptr;
21
22
23 if(ptr == NULL || s == NULL)
printf("malloc error!\n");
26 exit(1);
27 }
28 memset(ptr,0,MAX_LEN);
29 memset(s,0,MAX_LEN);
30
31
32 while(*p_temp != '\0')
33 {
34 if((*p_temp >= '0') && (*p_temp <= '9'))
35 {
36 count++;
37
38 }
39 if(count > max)
40 {
41 max = count;
42 s_temp = s;
43 s = p_temp - count;
44 for(i = 0;i < count;i++)
45 {
46 *(s + i) = *(p_temp + i);
47 }
48 *(s + i)= '\0';
49 }
50 else
51 {
52 count = 0;
53 }
54 p_temp++;
55 }
56
57 printf("the max count is:%d\n",max);
58 printf("%s\n",s_temp);
59
60 free(ptr);
61 free(s);
62 ptr = NULL;
63 s = NULL;
64 }