首页 技术 正文
技术 2022年11月17日
0 收藏 366 点赞 3,593 浏览 770 个字

本章标题是字符串和字符串函数。主要是了解和字符串有关的函数。

1.字符串表示和字符串I/O

  主要内容:字符串常量和字符串数组的初始化,对比了指针和字符串。

  其中要注意的是,数组初始化是从静态存储区把一个字符串复制给数组,而指针初始化只是复制字符串的地址。但是绝大多数的C字符串操作使用的都是指针。

2.字符串的函数

  无论怎么样,先分配足够的空间。介绍了三种输入函数gets()、fgets()、scanf()和三种输出函数puts()、fputs()、printf(),以及strlen()、strcat()等函数。

  

/* mod_str.c -- modify a string */#include <stdio.h>#include <string.h>#include <ctype.h>#define Limit 80void ToUpper (char *);int PunctCount(const char *);int main (void) {char line[Limit];puts ("Please enter a line:");gets (line);ToUpper (line);puts (line);printf ("That line has %d punctuation characters.\n", PunctCount (line));return 0;}void ToUpper (char * str){while (*str){*str = toupper (*str);str++;}}int PunctCount (const char * str){int ct = 0;while (*str){if (ispunct (*str))ct++;str++;}return ct;}

  这个代码充分体现了指针的简洁性。细细体会。

不过c语言处理字符串总的来说还是挺麻烦,还是Python大法好。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,121
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,593
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,438
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,209
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,845
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,930