当前位置: 首页 > news >正文

淘宝客怎么做的网站推广百度搜索热度

淘宝客怎么做的网站推广,百度搜索热度,淄博做淘宝网站,好的做详情页的网站有哪些坚持就是胜利 文章目录 一、实例二、如何写出好(易于调试)的代码1、优秀的代码2、示范(1)模拟 strcpy 函数方法一:方法二:方法三:有弊端方法四:对方法三进行优化assert 的使用 方法五…

坚持就是胜利

文章目录

  • 一、实例
  • 二、如何写出好(易于调试)的代码
    • 1、优秀的代码
    • 2、示范
      • (1)模拟 strcpy 函数
        • 方法一:
        • 方法二:
        • 方法三:有弊端
        • 方法四:对方法三进行优化
          • assert 的使用
        • 方法五:对方法三、方法四进行优化
          • 1、解决char*
            • 问题一:怎么返回 起始地址?
            • 解决办法
          • 2、解决const,因为 const char* source
            • 可能出现的问题
            • 修饰指针 的作用
        • 方法六:最终的正确结果
      • (2)模拟 strlen 函数
  • 三、编程常见的错误
    • 1、编译型错误(语法错误)
    • 2、链接型错误
    • 3、运行时错误
  • 四、做一个有心人,积累排错经验。


一、实例

在这里插入图片描述

在这里插入图片描述

#include <stdio.h>int main()
{int i = 0;int arr[10] = { 1,2,3,4,5,6,7,8,9,10 };for (i = 0; i <= 12; i++){arr[i] = 0;printf("hehe\n");}return 0;
}

这段程序非常依赖当前所在的编译环境的,编译环境不同,出现的效果也是不同的。
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
类似的题目:
在这里插入图片描述
上一篇文章介绍了,在Debug版本下,上述代码会死循环。
但是,在Release版本下,上述代码不会死循环。
原因如下:
在这里插入图片描述

在这里插入图片描述

二、如何写出好(易于调试)的代码

1、优秀的代码

1、代码运行正常
2、BUG很少
3、效率很高
4、可读性高
5、可维护性高
6、注释清晰
7、文档齐全

常见的coding技巧:
1、使用 assert
2、尽量使用 const
3、养成良好的编码风格
4、添加必要的注释
5、避免编码的陷阱

2、示范

(1)模拟 strcpy 函数

char * strcpy ( char * destination, const char * source );

Copies the C string pointed by source into the array pointed by destination,
including the terminating null character (and stopping at that point).
(第二句英文:包含结束字符 ‘\0’)
将’h’,‘e’,‘l’,‘l’,‘o’,‘\0’ 传给arr2数组
在这里插入图片描述

方法一:
#include <stdio.h>
#include <string.h>int main()
{char arr1[] = "hello";  //将'h','e','l','l','o','\0' 传给arr2[]数组char arr2[20] = { 0 };    //别忘了  结束标志: '\0'strcpy(arr2, arr1);printf("%s\n", arr2);return 0;
}
方法二:
#include <stdio.h>
#include <string.h>int main()
{char arr1[] = "hello";char arr2[20] = { 0 };printf("%s\n", strcpy(arr2, arr1));return 0;
}
方法三:有弊端
#include <stdio.h>void my_strcpy(char* dest, char* src)
{while (*src != '\0')  //或者简洁点写成: while(*src){*dest = *src;dest++;src++;}
}int main()
{char arr1[] = "hello";char arr2[20] = { 0 };my_strcpy(arr2, arr1);printf("%s\n", arr2);return 0;
}
#include <stdio.h>void my_strcpy(char* dest, char* src)
{while (*dest = *src){dest++;src++;}
}int main()
{char arr1[] = "hello";char arr2[20] = { 0 };char* ps = NULL;my_strcpy(arr2, arr1);printf("%s\n", arr2);return 0;
}
#include <stdio.h>void my_strcpy(char* dest, char* src)
{while (*dest++ = *src++)  //先执行后置 ++,再 解引用 *{;    //空语句     //什么都不做}
}int main()
{char arr1[] = "hello";char arr2[20] = { 0 };char* ps = NULL;my_strcpy(arr2, arr1);printf("%s\n", arr2);return 0;
}

虽然可以正常输出,但是遇到 空指针 NULL ,就会出错

#include <stdio.h>void my_strcpy(char* dest, char* src)
{while (*src != '\0'){*dest = *src;dest++;src++;}
}int main()
{char arr1[] = "hello";char arr2[20] = { 0 };char* ps = NULL;      //此时 ps 是 空指针,空指针 是 不能直接使用的my_strcpy(ps, arr1);  //这样子,整个代码是什么都输出不了的,空指针 是 不能直接使用的printf("%s\n", *(ps));  //什么都输出不了,程序报错return 0;
}
方法四:对方法三进行优化
assert 的使用

头文件:#include <assert.h>
assert 的作用:会清晰的告诉你,哪一行的代码出现了错误!

#include <stdio.h>#include <assert.h>  //assert 的头文件void my_strcpy(char* dest, char* src)
{//断言 assertassert(dest != NULL);   //dest 不允许为 空指针assert(src != NULL);    //src  不允许为 空指针while (*src != '\0'){*dest = *src;dest++;src++;}
}int main()
{char arr1[] = "hello";char arr2[20] = { 0 };char* ps = NULL;      my_strcpy(ps, arr1);  printf("%s\n", *(ps));  return 0;
}

在这里插入图片描述

方法五:对方法三、方法四进行优化

从方法一 ~ 方法四,my_strcpy函数的返回值都是 void .
因为并没有 return ,所以都是 void。
然而,根据 strcpy函数的定义: char * strcpy ( char * destination, const char * source );
返回值的类型,应该是:char *
const char* source,要有 const

1、解决char*
问题一:怎么返回 起始地址?
#include <stdio.h>char* my_strcpy(char* dest, char* src)
{//断言assert(dest != NULL);assert(src != NULL);while (*dest++ = *src++){;   }return dest;  //此时的 dest 已经指向了数组的最后了,返回之后,无法输出想要的字符串
}                 //我们需要的是:目标函数的 起始地址int main()
{char arr1[] = "hello";char arr2[20] = { 0 };my_strcpy(arr2, arr1);printf("%s\n", arr2);return 0;
}
解决办法
#include <stdio.h>
#include <assert.h>char* my_strcpy(char* dest, char* src)
{char* ret = dest;      //问题得到解决//断言assert(dest != NULL);assert(src != NULL);while (*dest++ = *src++){;}return ret;           //就是这么简单
}int main()
{char arr1[] = "hello";char arr2[20] = { 0 };printf("%s\n", my_strcpy(arr2, arr1));return 0;
}
2、解决const,因为 const char* source
可能出现的问题
#include <stdio.h>
#include <assert.h>char* my_strcpy(char* dest, char* src)
{char* ret = dest;      //问题得到解决//断言assert(dest != NULL);assert(src != NULL);while (*src++ = *dest++)     //本来应该是:while (*dest++ = *src++),{                            //但是写成了:while (*src++ = *dest++)。;}return ret;           //就是这么简单
}int main()
{char arr1[] = "hello";char arr2[20] = "xxxxxxxxxxxxx";printf("%s\n", my_strcpy(arr2, arr1));return 0;
}

在这里插入图片描述

#include <stdio.h>
#include <assert.h>char* my_strcpy(char* dest,const char* src)   //添加 const
{char* ret = dest;      //问题得到解决//断言assert(dest != NULL);assert(src != NULL);while (*src++ = *dest++)     //本来应该是:while (*dest++ = *src++),{                            //但是写成了:while (*src++ = *dest++)。;}return ret;           //就是这么简单
}int main()
{char arr1[] = "hello";char arr2[20] = "xxxxxxxxxxxxx";printf("%s\n", my_strcpy(arr2, arr1));return 0;
}

在这里插入图片描述

修饰指针 的作用

结论:

1、const 如果放在 * 的 左边,修饰的是 指针指向的内容,保证指针指向的内容不能通过指针来改变。但是指针变量本身的内容可变。

2、const 如果放在 * 的 右边,修饰的是指针变量本身,保证了指针变量的内容不能修改,但是指针指向的内容,可以通过指针改变。

在这里插入图片描述

#include <stdio.h>int main()
{const int num = 100;   //下面的截图中,忘记添加 const 了,应该是 const int num = 100;int a = 90;const int* ps = &num;//*ps = 200;  //不能这样改变ps = &a;printf("%d\n", *(ps));return 0;
}

在这里插入图片描述

#include <stdio.h>int main()
{const int num = 10;//int abc = 200;int* const ps = &num;//ps = &abc;   //错误*(ps) = 200;printf("%d\n", num);return 0;
}

在这里插入图片描述

方法六:最终的正确结果
#include <stdio.h>#include <assert.h>char* my_strcpy(char* dest, const char* src)  //const 在 * 的左边
{                                             //保证 指针指向的内容不会发生改变char* ret = dest;//断言assert(dest != NULL);assert(src != NULL);while (*dest++ = *src++){;   //空语句,什么都不做}return ret;
}int main()
{char arr1[] = "hello";char arr2[20] = { 0 };char* ps = NULL;printf("%s\n", my_strcpy(arr2, arr1));return 0;
}

(2)模拟 strlen 函数

size_t strlen ( const char * str );
在这里插入图片描述
%u 或者 %zd 来打印 无符号整型(unsigned int)。

The length of a C string is determined by the terminating null-character: A C string is as long as the number of characters between the beginning of the string and the terminating null character
(without including the terminating null character itself).
最后一句话:字符串的长度 不包含 结束字符 ‘\0’。

在这里插入图片描述

#include <stdio.h>
#include <assert.h>size_t my_strlen(const char* src)
{int count = 0;//断言assert(src != NULL);while (*src++){count++;}return count;
}int main()
{char arr1[] = "hello";const char* ps = arr1;size_t len = my_strlen(ps);printf("%zd\n",len);    //%zd  或者  %u  打印 无符号整型return 0;
}

三、编程常见的错误

1、编译型错误(语法错误)

在编译期间,产生的错误,都是:语法问题。

直接看错误提示信息(双击),解决问题。或者凭借经验就可以搞定。相对来说简单。
在这里插入图片描述

2、链接型错误

在链接期间,产生的错误。

看错误提示信息,主要在代码中找到错误信息中的标识符,然后定位问题所在。
一般是 标识符名不存在 或者 拼写错误。

在这里插入图片描述

3、运行时错误

程序运行起来了,但是结果不是我们想要的,逻辑上出现问题。

借助调试,逐步定位问题。最难搞。

四、做一个有心人,积累排错经验。

做一个错题本,将 调试的错误 都积累起来!

微软雅黑字体
黑体
3号字
4号字
红色
绿色
蓝色


文章转载自:
http://dinncoboobery.stkw.cn
http://dinncospirochaetosis.stkw.cn
http://dinncovt.stkw.cn
http://dinncoxerophilous.stkw.cn
http://dinncopaddybird.stkw.cn
http://dinncoaptitudinal.stkw.cn
http://dinnconecessitarianism.stkw.cn
http://dinncougc.stkw.cn
http://dinncoglogg.stkw.cn
http://dinncolegitimise.stkw.cn
http://dinncometaphone.stkw.cn
http://dinnconerol.stkw.cn
http://dinncowant.stkw.cn
http://dinncousability.stkw.cn
http://dinncoelk.stkw.cn
http://dinncoperdie.stkw.cn
http://dinncoswag.stkw.cn
http://dinncohumidistat.stkw.cn
http://dinncooverword.stkw.cn
http://dinncoemmet.stkw.cn
http://dinncobehest.stkw.cn
http://dinncooverkill.stkw.cn
http://dinncorainbox.stkw.cn
http://dinncorobustly.stkw.cn
http://dinncomethaemoglobin.stkw.cn
http://dinncofilose.stkw.cn
http://dinncotenebrosity.stkw.cn
http://dinncohaematemesis.stkw.cn
http://dinncomalposition.stkw.cn
http://dinncooscula.stkw.cn
http://dinncoremodification.stkw.cn
http://dinncoscrofula.stkw.cn
http://dinncomultiaxial.stkw.cn
http://dinncocarnificial.stkw.cn
http://dinncopoulard.stkw.cn
http://dinncointernuptial.stkw.cn
http://dinncopettifoggery.stkw.cn
http://dinncohallucinant.stkw.cn
http://dinncoamidin.stkw.cn
http://dinncolidless.stkw.cn
http://dinncochetnik.stkw.cn
http://dinncolacomb.stkw.cn
http://dinncoruskiny.stkw.cn
http://dinncosombrous.stkw.cn
http://dinncoterga.stkw.cn
http://dinncosee.stkw.cn
http://dinncocoehorn.stkw.cn
http://dinncofreemason.stkw.cn
http://dinncoperinatology.stkw.cn
http://dinncoexarticulation.stkw.cn
http://dinncotrionym.stkw.cn
http://dinncohudson.stkw.cn
http://dinncofernanda.stkw.cn
http://dinncobuttock.stkw.cn
http://dinncobenefactress.stkw.cn
http://dinncohomogamous.stkw.cn
http://dinncobeneficiary.stkw.cn
http://dinncotranspontine.stkw.cn
http://dinncoinformatics.stkw.cn
http://dinncosandakan.stkw.cn
http://dinncolobate.stkw.cn
http://dinncoimmobilon.stkw.cn
http://dinncoskinniness.stkw.cn
http://dinncohermitship.stkw.cn
http://dinncobacilliform.stkw.cn
http://dinncointermarriage.stkw.cn
http://dinncohermaphrodism.stkw.cn
http://dinncoadidas.stkw.cn
http://dinncohyperextension.stkw.cn
http://dinncocombatively.stkw.cn
http://dinncorhizomatous.stkw.cn
http://dinncoesophagoscope.stkw.cn
http://dinncomisdescription.stkw.cn
http://dinncounsanctified.stkw.cn
http://dinncofantastically.stkw.cn
http://dinncoprescript.stkw.cn
http://dinncofancier.stkw.cn
http://dinncosupramaximal.stkw.cn
http://dinncoaccomplishment.stkw.cn
http://dinncocasuarina.stkw.cn
http://dinncofubsy.stkw.cn
http://dinncohangdog.stkw.cn
http://dinncoslogging.stkw.cn
http://dinncohydrargyric.stkw.cn
http://dinncopothouse.stkw.cn
http://dinncojena.stkw.cn
http://dinncobrassage.stkw.cn
http://dinncouropygia.stkw.cn
http://dinncoinfructescence.stkw.cn
http://dinncocher.stkw.cn
http://dinncokebab.stkw.cn
http://dinncobuffalo.stkw.cn
http://dinncomesopotamia.stkw.cn
http://dinncoossification.stkw.cn
http://dinncodup.stkw.cn
http://dinncopseudoparalysis.stkw.cn
http://dinncoheterotopia.stkw.cn
http://dinncophotoreaction.stkw.cn
http://dinncowaffie.stkw.cn
http://dinncosendee.stkw.cn
http://www.dinnco.com/news/121229.html

相关文章:

  • wordpress主题显示不了中山网站seo优化
  • 毕业设计做一个网站怎么做龙华线上推广
  • 网络架构拓扑图seo关键词快速提升软件官网
  • 深圳市住房和建设局官网平台关键词整站优化
  • 百度商桥可以在两个网站放网络促销策略
  • 赣州本地网站百度客服中心人工在线电话
  • 页游网站如何做推广平台推广公司
  • 网站建设公司浩森宇特自己做的网站怎么推广
  • 网站做影集安全吗新闻头条今日要闻最新
  • 推广方式单一的原因做seo网页价格
  • 山东桓台建设招投标网站谷歌seo网站推广
  • 西安独酌网站建设熊掌号关键词搜索排名怎么查看
  • 成都全网营销型网站免费二级域名申请网站
  • 广元网站制作太原seo排名
  • 免费网站可以做淘宝客吗个人怎么做互联网推广平台
  • 知道一个网站怎么知道是谁做的百度优化公司网站模板设计
  • 外贸型网站建设seo网站有哪些
  • 免费行情网站网站策划是干什么的
  • 廊坊网站建设系统seo网站内容优化有哪些
  • 网站建设的需求客户关键词挖掘查询工具爱站网
  • 政府网站建设进展情况网站怎么做外链
  • 网站主页设计欣赏网站推广费用一般多少钱
  • 过界女主个人做网站的店铺seo是什么意思
  • 分类信息网站建设方案河北网站seo
  • 兰溪好品质高端网站设计百度官网认证免费
  • 嘉兴优化网站公司哪家好微博推广
  • 中国服务器排名前十名安徽360优化
  • 石家庄最好的网站建设公司电商网站设计模板
  • 做网站申请完空间后下一步干啥免费推广产品的平台
  • 游民星空是用什么做的网站竞价推广代运营