puts()_C语言
puts()函数用来向标准输出设备, scanf函数是格式输入函数,即按用户指定的格式从键盘上把数据输入到指定的变量之中。
puts就是输出字符串啊。
int puts(
const char* string
);
MSDN的例子
/* PUTS.C: This program uses puts
* to write a string to stdout.
*/
#include <stdio.h>
void main( void )
{
puts( "Hello world from puts!" );
}
运行结果就是
Hello world from puts!
你要输出换行的话,就用 puts( "\n" );
用法很简单啊,就是把一个C样式的字符串当参数传过去。
//-----------------------------------------
我刚刚试过了
puts( "" )的确可以起到换行的作用。
The puts function writes string to the standard output stream stdout, replacing the string's terminating null character ('\0') with a newline character ('\n') in the output stream.
当puts遇到\0时,会输出一个\n,也就是换行。
所以puts( "" )时,因为字符串本身长度为0,所以第一个字符就是\0,puts会输出一个\n,所以起到了换行的效果。
也就是说, puts( "" )跟puts( "\0" )是等效的,也等效於printf( "\n" )
在gets();前面加一个getchar();因为scanf()输入后有一个回车,gets()接收的回车符,要加个getchar();就是为了接受那个回车符
举个例子:
char c[] = "good";
puts(c);
c中并没有换行符,但是puts打印玩good后会默认换行,这个换行就是它自己增加的,也就是老谭所说的意思。
char *gets( char *str );
puts就是输出字符串啊。
int puts(
const char* string
);
MSDN的例子
/* PUTS.C: This program uses puts
* to write a string to stdout.
*/
#include <stdio.h>
void main( void )
{
puts( "Hello world from puts!" );
}
运行结果就是
Hello world from puts!
你要输出换行的话,就用 puts( "\n" );
用法很简单啊,就是把一个C样式的字符串当参数传过去。
//-----------------------------------------
我刚刚试过了
puts( "" )的确可以起到换行的作用。
The puts function writes string to the standard output stream stdout, replacing the string's terminating null character ('\0') with a newline character ('\n') in the output stream.
当puts遇到\0时,会输出一个\n,也就是换行。
所以puts( "" )时,因为字符串本身长度为0,所以第一个字符就是\0,puts会输出一个\n,所以起到了换行的效果。
也就是说, puts( "" )跟puts( "\0" )是等效的,也等效於printf( "\n" )
最新文章
- 查找Maven JAR坐标
- 使用C#开发ActiveX控件(新)
- 【BZOJ-3910】火车 倍增LCA + 并查集
- NodeJS Hello world
- Using Post-Form Trigger In Oracle Forms
- js中singleton模式解析及运用
- 报错:ORA-02287: 此处不允许序号
- javascript this关键字
- SPOJ104 Highways,跨越数
- 前端MVC框架之 Angular
- golang channel无缓冲通道会发生阻塞的验证
- 201521123061 《Java程序设计》第三周学习总结
- UrlRewriter配置IIS支持伪静态
- Spring(5)——Spring 和数据库编程
- springboot2.0.3源码篇 - 自动配置的实现,发现也不是那么复杂
- 利用jQuery动态设置单选框的选中
- SpringMVC页面向Controller传参
- SQL 统计某一天的数据量时, 使用 dateValue(字段) 与 between 性能差异很明显。
- 实验十&#160;ZStack&#160;网状网络实验
- 先 FROM 后 WHERE 再 GROUP BY 再 SELECT 再 order BY
热门文章
- 在 ASP.NET Core 中自动启用 CAP 事务
- 改头换面为哪般,最像Android的Windows——Win11升级安装体验
- 洛谷3203 弹飞绵羊(LCT)
- Python内置高阶函数map()
- nio之缓冲区(Buffer)理解
- springboot多配置环境
- spring cloud config 结合 spring cloud bus实现配置自定的刷新
- 热身训练2 The All-purpose Zero
- 华为HG255D挂卡中继专用旋风科技固件
- vs2015 MSB600 ";inf2cat.ext";已退出,代码为2