学习总结

1、String str=”hello world!”;(Java),char[20]=” hello world!”;(C)。其实Java字符串的实现,也是字符数组。

2、字符串的尾部都会以空字符(\0)结束,所以” hello world! “这个字符数组的长度是13。<string.h>函数库有个strlen()函数可以计算机字符串的字符数组长度(不包括空字符\0)。

3、scanf(“%s”,name)和gets的差别:

 #include <stdio.h>
int main(void){
char name[];
printf("what's your name?\n");
scanf("%s",name);
printf("hello %s!\n",name);
return ;
}

运行结果:

what's your name?

tom green

hello tom!

 #include <stdio.h>
int main(void){
char name[];
printf("what's your name?\n");
gets(name);
printf("hello %s!\n",name);
return ;
}

运行结果:

what's your name?

tom green

hello tom green!

4、#define可用于常量定义,格式:#define NAME value,编译器在编译前会把所有NAME替换为value后在编译,相当于单纯“面值”的替换。如果value是组合元素的话,最好括号,如#define SUM (x+y),以防这种“文字游戏”引起的错乱。

5、C常量的另一种表示可以使用const关键字,如const int months=12。那么months就是一个常量了。总之const修饰的对象就是常量,不可以修改。

6、编程练习(题7):

 #include <stdio.h>
#define J2S 3.785
#define Y2G 1.609
int main(){
double mile,gallon;
printf("enter your mile:");
scanf("%lf",&mile);
printf("enter your gallon:");
scanf("%lf",&gallon);
printf("your oil wear is %.1f\n",mile/gallon);
printf("your CHN oil wear is %.1f\n",mile*Y2G/(gallon*J2S));
}

运行结果:

enter your mile:100

enter your gallon:50

your oil wear is 2.0

your CHN oil wear is 0.9

【C语言学习】《C Primer Plus》第4章 字符串和格式化输入/输出的更多相关文章

  1. C Primer Plus 第4章 字符串和格式化输入/输出 编程练习

    1. #include <stdio.h> int main(void) { ]; ]; printf("请输入您的名字: "); scanf("%s&quo ...

  2. c语言学习笔记第四章——字符串和格式化输入、输出

    B站有视频演示 本章学习printf函数的输入输出,字符串的定义与实用. 字符串 字符串(character string)是一个或多个字符的序列,如下所示: "Zing went the ...

  3. C Primer Plus学习笔记(三)- 字符串和格式化输入/输出

    从一个简单的例子开始 #include <stdio.h> int main() { char name[10]; printf("Input Your Name:\n" ...

  4. 重学C语言---04字符串和格式化输入/输出

    1.程序示例 //talkback.c一个能为你提供一些信息的对话框 #include <stdio.h> #include <string.h> //提供strlen函数原型 ...

  5. GO语言学习笔记1-输入带空格的字符串

    最近开始学习GO语言,并做了一些编程练习.有道题要输入带空格的字符串,这在C/C++中很容易实现,但GO中好像并不那么容易.学过C/C++的可能都知道,在C中可以使用gets()函数,在C++可以使用 ...

  6. c语言学习之基础知识点介绍(二):格式化控制符和变量的补充

    上节简单介绍了c语言中的一些基础知识点,本节将对之前介绍的不够详细的知识点进行补充. 格式化控制符的消息介绍: %d的其他控制符: 1.%md:m代表这个整数位占用多少位,m是一个整数.实际数字不足的 ...

  7. C语言学习之我见-strncat()可调整的字符串拼接函数

    strncat()函数,用于两个字符串的拼接. (1)函数原型 char * strncat(char * Dest,const char * Source,size_t _Count)` (2)头文 ...

  8. 【C语言学习】-05 二维数组、字符串数组、多维数组

    ⼆二维数组.字符串数组.多维数组

  9. R语言学习笔记(二十一):字符串处理中的元字符(代码展示)

    元字符有自己的特殊含义 [ ]内的任意字符将被匹配 grep(pattern = "[wW]", x = states, value = T) grep(pattern = &qu ...

随机推荐

  1. vios 虚拟光驱 安装vioc

    一.VIO server 创建虚拟光驱 1 检查是否创建Library $lsrep 2 创建 VMLibrary :vg 和size都可以自己定义 $mkrep -sp rootvg -size 1 ...

  2. HTTP协议-----小白

    HTTP是一个属于应用层的面向对象的协议. ***OSI的7层从上到下分别是 7 应用层 6 表示层 5 会话层 4 传输层 3 网络层 2 数据链路层 1 物理层 HTTP协议的主要特点可概括如下: ...

  3. .net 常用的命名空间和类

    一.基础命名空间 l  System.Collections 包含了一些与集合相关的类型,比如列表,队列,位数组,哈希表和字典等. l  System.IO 包含了一些数据流类型并提供了文件和目录同步 ...

  4. 关于json解析中 解析多重json对象

    JSONObject rst = {"AIS-RST":"AIS-00000001","AIS-STATUS":"AIS-0000 ...

  5. 【13-Annotation】

    Annotation 5个基本的Annotation •@Override •@Deprecated •@SuppressWarnings •@SafeVarargs •@FunctionalInte ...

  6. redis sentinel基本命令与参数

    1.redis基本命令1)获取sentinel的状态(1)info查看sentinel的状态(2)sentinel masters 获取sentinel中监控的所有master的节点(3)sentin ...

  7. mysql下载安装

    1.下载 下载地址:http://dev.mysql.com/downloads/mysql/ 根据电脑配置来选,我选了 windows(x86,64-bit),ZIP Archive这个,点击Dow ...

  8. Gambler's Ruin Problem and 3 Solutions

    In my stochastic processes class, Prof Mike Steele assigned a homework problem to calculate the ruin ...

  9. Angular JS将数据显示为两列(html)

    (数据为Array数组)使用AngularJS中ng-show="{{}}",其将数据按行分为奇数行和偶数行,$even是判断是否为奇数行[如果是则为true,不是则为false] ...

  10. Centos7安装完毕后重启提示Initial setup of CentOS Linux 7 (core)的解决方法

    问题: CentOS7安装完毕,重新开机启动后显示: Initial setup of CentOS Linux 7 (core) 1) [x] Creat user 2) [!] License i ...