学习总结

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. 我利用网上代码开发的JQuery图片插件

    我利用网上代码开发的JQuery图片插件 代码如下 (function($){ $.fn.FocusPic = function(options){ var defaults = { interval ...

  2. 使用cookie实现计数器功能

    思路是:若第一次访问,创建cookie.若访问次数大于一,则先读出cookie值赋给一个值,然后再重新写入cookie. <?php if(!isset($_COOKIE['num'])){ $ ...

  3. js如何找到方法在哪个js文件

    在Console窗口中输入var f = methodA.prototype.constructor;console.log(f); 网络搜索到的方法.

  4. C#捕获c++异常

    摘自:http://bbs.csdn.net/topics/390665130 .net 40 中,c# 默认情况下只处理SEH的异常.不处理CSE的异常.若你要捕获这类的异常. [HandlePro ...

  5. C#实现:给定任意数字,输出在该数字下所有()括号的集合

    class Program { static void Main(string[] args) { getPairs(, , , , ""); Console.ReadKey(); ...

  6. 《CODE》书摘

    2016-11-08 14:59:16 可以说英语词汇就是一种编码. 2016-11-08 15:19:04 实际上任何两种不同的东西经过一定的组合都可以代表任何种类的信息. 2016-11-08 1 ...

  7. 多层嵌套ajax同步

    方式一: $.ajax({ type : "post", url : "user/add", data : data, async : false, //必须为 ...

  8. mysql galera cluster 集群的分裂与仲裁机制

    集群的分裂 当集群由于网络原因分裂为几个单独的组时(一组可能是单节点,也可能是几个互联的节点),数据出现不一致,此时可能产生脑裂及数据不一致.这种情况 下,只有一组节点能够继续提供服务,这组节点的状态 ...

  9. 第三章 文件IO复习

          open(const char * path, int flag.../*mode_t*/) #include <fcntl.h> path:绝对路径 flag:O_RDONL ...

  10. gem sources --add http://ruby.taobao.org/

    gem sources  gem sources  gem sources --remove http://ruby.taobao.org/ gem sources --add http://ruby ...