)
第1讲答疑.mp4案例如何将数值存储到指定的内存地址比如用scanf接收一个地址然后存储数据到这个地址。#includestdio.hintmain(){inta10;intb20;int*p;printf(a%x,b%x\n,a,b);scanf(%p,p);//把接收到的地址存储到p里*p99;printf(a%d,b%d\n,a,b);return0;}效果如下:第2讲综合习题1删除字符删除字符串.mp4案例1删除字符串中的指定字符。#includestdio.hintmain(){charstr[30]hello yicheng hello book;charcho;//删除字符串中的字符ochar*pstr;while(*p){//或用*p!\0if(*pch){//如果指针处字符等于ch则把后面字符全部往前移一位char*p1p;char*p2p1;while(*p2){*p1*p2;p1;p2;}*p1\0;//末尾加上空字符}else{p;//如果指针处字符不等于ch则指针往后移}}printf(%s\n,str);return0;}结果为案例2删除字符串中的指定字符串。#includestdio.h#includestring.hintmain(){charstr[50]ABC hello yicheng hello book hello cpp hello;charstr2[10]hello;//删除字符串中的“hello”char*pstr;intlenstrlen(str2);while((pstrstr(str,str2))!NULL){//只要能找到字符串就继续否则退出char*p1p;//找到字符串后后面的字符往前移动len个字节char*p2plen;while(*p2){*p1*p2;p1;p2;}*p1\0;//在末尾加上空字符}printf(%s\n,str);return0;}结果为第3讲综合习题2判定QQ是否运行.mp4案例判断进程中是否有QQ在运行。需要用到管道机制#define_CRT_SECURE_NO_WARNINGS#includestdio.h#includestdlib.h#includestring.hvoidexecmd(char*cmd,char*str){charbuf[128]{0};//定义一个字符缓冲区FILE *p_popen(cmd,r);//创建一个管道执行指令把管道当作文件来处理r就是把文件按照读的方式来操作if(pNULL){puts(error);}else{while(!feof(p)){//判断是否到了文件末尾到了末尾返回非0否则返回0if(fgets(buf,128,p)){//把文件读入缓冲区strcat(str,buf);//链接/追加/拼接字符串}}_pclose(p); //关闭管道}}intmain(){charstr[8096]{0};execmd(tasklist,str);printf(%s\n,str);if(strstr(str,QQ.exe)NULL){puts(NO QQ);}else{puts(Have QQ);}return0;}效果如下第4讲综合习题3实现内存拷贝memcpy.mp4案例自定义一个函数实现memcpy函数的内存拷贝功能。#define_CRT_SECURE_NO_WARNINGS#includestdio.h#includestdlib.h#includestring.hvoid*mymemcpy(void*dst,constvoid*src,unsignedintsize){//const避免传入的数据被意外修改char*pdst;//把空类型指针转化为字符指针constchar*ssrc;//src为const类型因此s定义为const类型才能匹配。while(size--){*p*s;}returndst;}intmain(){charstr1[30]********************;charstr2[30]12345678910111212;mymemcpy(str1,str2,9);printf(%s\n,str1);return0;}结果为