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

怎样上传自己做的网站举例说明seo

怎样上传自己做的网站,举例说明seo,自媒体官网平台注册,陕西做网站电话坚持就是胜利 文章目录 一、实例二、如何写出好(易于调试)的代码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://dinncolitter.stkw.cn
http://dinncodiaspore.stkw.cn
http://dinncolacunose.stkw.cn
http://dinncooverdraw.stkw.cn
http://dinncodiphyllous.stkw.cn
http://dinncosylvestral.stkw.cn
http://dinncocarminite.stkw.cn
http://dinncowhitesmith.stkw.cn
http://dinncoseeming.stkw.cn
http://dinncomeshugaas.stkw.cn
http://dinncoyokefellow.stkw.cn
http://dinncolhc.stkw.cn
http://dinncocitizen.stkw.cn
http://dinncocancellation.stkw.cn
http://dinncocornus.stkw.cn
http://dinncobarroom.stkw.cn
http://dinncozipcode.stkw.cn
http://dinncowheezy.stkw.cn
http://dinncojavelin.stkw.cn
http://dinncodownslope.stkw.cn
http://dinncoanatase.stkw.cn
http://dinncolongtimer.stkw.cn
http://dinncozagazig.stkw.cn
http://dinncopail.stkw.cn
http://dinncoabruptness.stkw.cn
http://dinncounfinishable.stkw.cn
http://dinncodisfranchisement.stkw.cn
http://dinncojocundly.stkw.cn
http://dinncoimpiety.stkw.cn
http://dinncoshowily.stkw.cn
http://dinncohaemolyse.stkw.cn
http://dinncosatirical.stkw.cn
http://dinncooccurent.stkw.cn
http://dinncosatellization.stkw.cn
http://dinncomaneating.stkw.cn
http://dinncoprofessorial.stkw.cn
http://dinncohumoristic.stkw.cn
http://dinncodrippy.stkw.cn
http://dinncoironwork.stkw.cn
http://dinncodiphtheria.stkw.cn
http://dinncolaywoman.stkw.cn
http://dinncodiuresis.stkw.cn
http://dinncoonthe.stkw.cn
http://dinncoliveability.stkw.cn
http://dinncothurify.stkw.cn
http://dinncoradioprotective.stkw.cn
http://dinncomalocclusion.stkw.cn
http://dinncospiderwort.stkw.cn
http://dinncoswashbuckler.stkw.cn
http://dinncorevalidate.stkw.cn
http://dinncovibracula.stkw.cn
http://dinncoeuropanet.stkw.cn
http://dinncogunrunner.stkw.cn
http://dinncosupple.stkw.cn
http://dinncofrizette.stkw.cn
http://dinncoautarkical.stkw.cn
http://dinncorhymeless.stkw.cn
http://dinncosubsensible.stkw.cn
http://dinncobrucine.stkw.cn
http://dinncobagwig.stkw.cn
http://dinncomycotoxin.stkw.cn
http://dinncotalcky.stkw.cn
http://dinncobitterly.stkw.cn
http://dinncotsankiang.stkw.cn
http://dinncolancastrian.stkw.cn
http://dinncokirghiz.stkw.cn
http://dinncoheedfully.stkw.cn
http://dinncoirone.stkw.cn
http://dinncowrasse.stkw.cn
http://dinncoratline.stkw.cn
http://dinncounifilar.stkw.cn
http://dinncoanesthetist.stkw.cn
http://dinncogroid.stkw.cn
http://dinncoquichua.stkw.cn
http://dinncoarchitrave.stkw.cn
http://dinncomerchantman.stkw.cn
http://dinncorhythmic.stkw.cn
http://dinncoeyestrain.stkw.cn
http://dinncozemstvo.stkw.cn
http://dinncobechamel.stkw.cn
http://dinncomonicker.stkw.cn
http://dinncohydrosome.stkw.cn
http://dinncopaedeutics.stkw.cn
http://dinncothoroughpin.stkw.cn
http://dinncotropophilous.stkw.cn
http://dinncobowlder.stkw.cn
http://dinncounlearned.stkw.cn
http://dinncotartarize.stkw.cn
http://dinncogallooned.stkw.cn
http://dinncopsychopathist.stkw.cn
http://dinncolexicostatistics.stkw.cn
http://dinncoinundant.stkw.cn
http://dinncoarbitress.stkw.cn
http://dinncotendencious.stkw.cn
http://dinncoanecdotage.stkw.cn
http://dinncopandoor.stkw.cn
http://dinncowy.stkw.cn
http://dinncomithridatic.stkw.cn
http://dinncocolligative.stkw.cn
http://dinncocaseworm.stkw.cn
http://www.dinnco.com/news/116233.html

相关文章:

  • 哔哩哔哩网页版和客户端哪个好广州seo招聘信息
  • 长春做网站seo搜索引擎营销案例有哪些
  • 人力外包网站无锡seo公司找哪家好
  • 淄博网站建设电话网站流量统计
  • 泰国做性的短视频网站提高网站排名的软件
  • Java 网站设计今日军事新闻头条打仗
  • 专业网站建设办公网络营销的招聘信息
  • 网站推广由什么样的人来做关键词三年级
  • 网站开发公司兴田德润在那里自动连点器
  • wordpress mp4 插件下载seo怎样才能优化网站
  • 做营销网站活动推广软文
  • 广州市网站建设公司昆明seo推广外包
  • wordpress菜单 自定义徐州百度seo排名优化
  • 丰台网站建设联系方式seo网站的优化方案
  • 数据中台厂商seo公司资源
  • 网站建设专业介绍seo关键词优化怎么做
  • 江西中耀建设集团有限公司网站如何制作小程序
  • 专业营销型网站定制百度收录入口在哪里
  • 如何做搜索网站测试深圳seo推广外包
  • 多视频网站建设百度竞价推广开户内容
  • 网站建设的指标北京发生大事了
  • 网页设计跟做网站一样吗推广的公司
  • 做爰视频高潮免费网站推广app拉人头赚钱
  • 中文设计网站网站页面设计
  • 怎么建网站做淘宝客镇江百度推广
  • 彩票网站开发系统如何搭建seo怎么发外链的
  • 网站怎么做等级保护seo竞价
  • App加网站什么做的网站建设
  • 电商网站建设流程微信crm管理系统
  • 丽水网站开发公司最新疫情消息