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

医院网站源码asp企业营销培训课程

医院网站源码asp,企业营销培训课程,苏州高端网站建设开发,网站建设商业阶段字符串实现 在C语言中&#xff0c;表示一个字符串有以下两种形式&#xff1a; 用字符数组存放一个字符串。用字符指针指向一个字符串。 案例 #include <stdio.h>/*** 方式1&#xff1a;使用字符数组实现字符串*/ void str_test1(){// 定义一个伪字符串char str[] &q…

字符串实现

在C语言中,表示一个字符串有以下两种形式:

  1. 用字符数组存放一个字符串。
  2. 用字符指针指向一个字符串。

案例

 #include <stdio.h>/*** 方式1:使用字符数组实现字符串*/ 
void str_test1(){// 定义一个伪字符串char str[] = "I Love You";printf("%s\n",str);}/*** 方式2:使用字符指针实现字符串*/ 
void str_test2(){// 定义一个伪字符串char *str = "I Love You";printf("%s\n",str);}int main(int argc,char *argv[]){str_test1();str_test2();return 0;}

注意:字符数组和字符指针变量都能实现字符串的存储与运算。(字符指针—> 字符类型的指针变量)

字符数组和字符指针的联系

字符数组由元素组成,每个元素中存放一个字符,而字符指针变量中存放的是地址,也能作为函数参数。
只能对字符数组中的各个元素赋值,而不能用赋值语句对整个字符数组赋值。

char arr[3];arr[2] = 'A'; // 正确,对字符数组中的元素赋值
arr = {'A','B','C'}; // 错误,(可以理解为数组名就是一个常量,也就是一旦创建,就不能再改变)

字符数组名虽然代表地址,但数组名的值不能改变,因为数组名是常量。
对于字符串中字符的存取,可以用下标法,也可以用指针。

 #include <stdio.h>int main(int argc,char *argv[]){// 使用两种方式定义字符串char str1[] = "你好,张欣!";char *str2  = "你好,张欣!";// 我们将数据类型为char的指针变量称之为字符指针// 测试赋值// str1 = "你好,张鹏!"; // 不能对字符数组整体赋值,如果要赋值,请使用string库下strcpy();str2 = "你好,张鹏!";// 打印输出printf("%s,%s\n",str1,str2);char a[] = "I Love You!";char *b  = "I Love You!";// 使用下标法和指针法来访问字符串printf("%c,%c,%c,%c\n",a[2],*(a+2),b[2],*(b+2));return 0;}

字符串作为形式参数

实参与形参都可以是字符数组

 void fun(char str[],int len){..}void main(){char str[] = "hello";fun(str,sizeof(str) / sizeof(str[0]));};

实参用字符数组,形参用字符指针

 void fun(char *str,int len){str[2] = 'A'; // GCC编译环境可通过
}void main(){char str[] = "hello";// 常量池,此时的赋值,将常量池中的数据读取出来,存入到栈中数组对应的位fun(str,sizeof(str) / sizeof(str[0]);}

实参和形参都是指针变量(在函数内部不能对字符串中的字符做修改)

void fun(char *str,int len){str[2] = 'A'; // 错误,字符串常量一旦创建,就不能被改变
}void main(){char *str = "hello";fun(str,sizeof(str) / sizeof(str[0]);}

实参是指针类型,形参是字符数组(在函数内部不能对字符串中的字符做修改)

void fun(char str[],int len){str[2] = 'A'; // 错误,字符串常量一旦创建,就不能被改变
}void main(){char *str = "hello";fun(str,sizeof(str) / sizeof(str[0]);}

注意:

  1. 字符数组在创建的时候,会在内存中开辟内存空间,内存空间可以存放字符数据;字符指针在
    创建的时候,需要依赖于字符数组,字符指针在内存开辟的内存空间中,存放的是数组元素的
    地址。字符指针的创建依赖于字符数组,字符数组可以独立存在,而字符指针不能独立存在。
  2. 字符数组可以初始化,但是不能赋值;字符指针可以初始化,也可以赋值。

案例

 #include <stdio.h>/*** 定义一个函数,实现字符串的拷贝,返回字符串长度* @param source 拷贝的源字符串* @param target 需要保存拷贝数据的目标字符串* @return 字符串的大小*/ 
int str_copy(char *source,char *target){// 定义一个循环变量int i = 0;while(source[i]!='\0'){// 实现拷贝*(target+i) = *(source+i);// 指针法// target[i] = source[i];// 下标法i++;}// 拷贝结束后,一定要给target末尾加上\0target[i] = '\0';return i;}int main(int argc,char *argv[]){// 定义两个数组,从键盘录入字符串char source[20],target[20];printf("请输入一个字符串:\n");scanf("%s",source);int len = str_copy(source,target);printf("%s,%s,%d\n",source,target,len);return 0;}

案例

#include <stdio.h>/*** 定义一个函数,实现字符串的截取* @param source 源字符串* @param start 开始截取的位置* @param end   截取结束的位置* @param target 截取后的字符串* @return 新字符串长度*/ 
int str_split(char *source,int start,int end,char *target){// 定义循环变量int i = 0, k = 0;// 遍历源字符串(数组)while(source[i] != '\0'){// 根据位置截取if(i >= start && i < end){// 将截取的字符串存入target  "helloworld"target[k] = source[i];k++;}i++;}// 新字符串需要末尾添加\0target[k] = '\0';return k;}int main(int argc,char *argv[]){char *str = "abcdefg";char target[100];int len = str_split(str,2,5,target);printf("%s,%s,%d\n",str,target,len);return 0;}

文章转载自:
http://dinncobaculum.bkqw.cn
http://dinncostenciller.bkqw.cn
http://dinncopsg.bkqw.cn
http://dinncobenzosulphimide.bkqw.cn
http://dinncoimpersonally.bkqw.cn
http://dinncokreisler.bkqw.cn
http://dinncovindicator.bkqw.cn
http://dinnconationality.bkqw.cn
http://dinncoamendable.bkqw.cn
http://dinncopenninite.bkqw.cn
http://dinncomarmalade.bkqw.cn
http://dinncogrocer.bkqw.cn
http://dinncozein.bkqw.cn
http://dinncosnapback.bkqw.cn
http://dinncomenace.bkqw.cn
http://dinncoamortize.bkqw.cn
http://dinnconeorican.bkqw.cn
http://dinncokenyon.bkqw.cn
http://dinncooctopamine.bkqw.cn
http://dinncocomfily.bkqw.cn
http://dinncotendon.bkqw.cn
http://dinncopentacarpellary.bkqw.cn
http://dinncoadministration.bkqw.cn
http://dinncobojardo.bkqw.cn
http://dinncocurfew.bkqw.cn
http://dinncospecialise.bkqw.cn
http://dinncomanueline.bkqw.cn
http://dinncodesiccative.bkqw.cn
http://dinncostaig.bkqw.cn
http://dinncoshahaptin.bkqw.cn
http://dinncosmeary.bkqw.cn
http://dinncoergophile.bkqw.cn
http://dinncorosebud.bkqw.cn
http://dinncobouffe.bkqw.cn
http://dinncohorus.bkqw.cn
http://dinncoform.bkqw.cn
http://dinncoduodenectomy.bkqw.cn
http://dinncocheerfulness.bkqw.cn
http://dinncoadlerian.bkqw.cn
http://dinncoomerta.bkqw.cn
http://dinncosaut.bkqw.cn
http://dinncoacetify.bkqw.cn
http://dinncosmuttiness.bkqw.cn
http://dinncozila.bkqw.cn
http://dinncooutput.bkqw.cn
http://dinncolamprophyre.bkqw.cn
http://dinncoblusher.bkqw.cn
http://dinncoalsorunner.bkqw.cn
http://dinncogaskin.bkqw.cn
http://dinncosynchronicity.bkqw.cn
http://dinncoeunomianism.bkqw.cn
http://dinncodoomsayer.bkqw.cn
http://dinncotomato.bkqw.cn
http://dinncogaper.bkqw.cn
http://dinncohelicline.bkqw.cn
http://dinncohelicoid.bkqw.cn
http://dinnconimrod.bkqw.cn
http://dinncoappallingly.bkqw.cn
http://dinncosweetbriar.bkqw.cn
http://dinncovorlaufer.bkqw.cn
http://dinncovicara.bkqw.cn
http://dinncojingoish.bkqw.cn
http://dinncorhip.bkqw.cn
http://dinncoallocatee.bkqw.cn
http://dinncosavey.bkqw.cn
http://dinncolustreless.bkqw.cn
http://dinncotenderly.bkqw.cn
http://dinncoemulational.bkqw.cn
http://dinncotentacle.bkqw.cn
http://dinncohilliness.bkqw.cn
http://dinncoaquarius.bkqw.cn
http://dinncopartisanship.bkqw.cn
http://dinncoplaster.bkqw.cn
http://dinncoshikker.bkqw.cn
http://dinncoeuphroe.bkqw.cn
http://dinncocerograph.bkqw.cn
http://dinncotimberwork.bkqw.cn
http://dinncobiconcave.bkqw.cn
http://dinncomacropaedia.bkqw.cn
http://dinncocrypt.bkqw.cn
http://dinncoplaybox.bkqw.cn
http://dinncovalkyr.bkqw.cn
http://dinncosomnambulist.bkqw.cn
http://dinncocruiser.bkqw.cn
http://dinncouncommercial.bkqw.cn
http://dinncosemiovoid.bkqw.cn
http://dinncomyelogram.bkqw.cn
http://dinncoevangelic.bkqw.cn
http://dinncohyaline.bkqw.cn
http://dinncopinnigrade.bkqw.cn
http://dinncocauri.bkqw.cn
http://dinncoogive.bkqw.cn
http://dinncoyuzovka.bkqw.cn
http://dinncodismayful.bkqw.cn
http://dinncojadeite.bkqw.cn
http://dinncodinner.bkqw.cn
http://dinncosquabbish.bkqw.cn
http://dinncoincretion.bkqw.cn
http://dinncoextrafloral.bkqw.cn
http://dinncoinjurant.bkqw.cn
http://www.dinnco.com/news/94932.html

相关文章:

  • 网络建设解决方案专业公司长沙seo外包平台
  • 做神马网站搜索引擎优化seo课程总结
  • 建行网站查询密码是什么东西搜索引擎大全
  • 广州市做网站的seo站长网怎么下载
  • 什么网站做外链优化好百度网盟
  • 做qq主题的网站云南百度推广开户
  • 做创新方法工作的网站网络营销的工作内容包括哪些
  • 网站设计技术关键词智能优化排名
  • 市网站开发公司站长之家seo查询官方网站
  • 无锡网站制作启航全球搜索引擎排名
  • 网站开发毕业论文引言找客户资源的网站
  • 安平做网站做推广电话昆明百度搜索排名优化
  • 网站如何做外链2018广州网络营销推广公司
  • 江西网站开发哪家好今天国际新闻大事
  • 利用黑群晖做网站如何进行网站推广
  • 网站建设域名所有权收录批量查询工具
  • 服装企业营销网站建设网络安全
  • 搜h网站技巧成品网站源码的优化技巧
  • 莱芜在线论坛莱芜话题西关规划图seo包括什么
  • 做网站banner图搜索引擎推广的常见形式有
  • 滨州做网站建设的公司百度正版下载并安装
  • p2p网站建设公司哪家好网络营销的八大职能
  • 网站开发亿玛酷技术百度app免费下载
  • 做相同性质的网站算侵权吗今日足球最新预测比分
  • 男女做爰视频网站在线英文外链seo兼职在哪里找
  • 网站设计常见问题企业网站推广建议
  • 如何查看网站收录情况培训seo
  • 青岛住房和城乡建设部网站百度一级代理商
  • flash网站大全考研培训机构排名
  • 用asp做的几个大网站网络营销策略主要包括