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 );
The gets() function reads characters from STDIN and loads them into str, until a newline or EOF is reached. The newline character is translated into a null termination. The return value of gets() is the read-in string, or NULL if there is an error.  
gets函数从标准输入设备读取字符串,直到遇到换行或者EOF。换行符被认为是终止字符。若函数调用成功,返回字符串;否则返回NULL。
 
int puts( char *str );
The function puts() writes str to STDOUT. puts() returns non-negative on success, or EOF on failure. 
puts函数项标准输出设备写出字符串。若成功调用,返回非负值;否则EOF。
 
注意:这两个函数都是c语言标准输入输出库中的函数,在使用时要包含<stdio.h>;在c++中应包括<cstdio>。同时这两个函数的参数都是字符数组,而不能用c++中的字符串对象。

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" )

puts()_C语言的更多相关文章

  1. 【书籍下载链接】_1_第一轮_C语言书籍

    各位朋友,如果您觉得下载的电子书,看的还可以,请购买纸质版的图书,如果您觉得 您下载的书,不值得一看请在下载后直接删除. Windows汇编:http://dl.vmall.com/c0jk1v970 ...

  2. 选择排序_C语言_数组

    选择排序_C语言_数组 #include <stdio.h> void select_sort(int *); int main(int argc, const char * argv[] ...

  3. 插入排序_C语言_数组

    插入排序_C语言_数组 #include <stdio.h> void insertSort(int *); int main(int argc, const char * argv[]) ...

  4. 快速排序_C语言_数组

    快速排序_C语言_数组 #include <stdio.h> void quickSort(int *, int, int); int searchPos(int *, int, int) ...

  5. 冒泡排序_C语言_数组

    冒泡排序_C语言_数组 #include <stdio.h> //冒泡排序 小->大 void sort(int * pArray, int len); int main(int a ...

  6. C++_系列自学课程_第_9_课_C语言风格字符串_《C++ Primer 第四版》

    前面说了写关于数组和指针的内容,这次在这里讨论一下字符串,讨论一下C语言风格的字符串. 在C语言里面我们利用字符数组来对字符串进行处理, 在C++里面我们前面说过一种类类型string可以对字符串进行 ...

  7. 160809209_李梦鑫_C语言程序设计实验3 循环结构程序设计

    <C语言程序设计>实验报告 学 号 160809209 姓 名 李梦鑫 专业.班 计科16-2班 学    期 2016-2017 第1学期 指导教师 黄俊莲 吉吉老师 实验地点 C05 ...

  8. 160809209_李梦鑫_C语言程序设计实验2+选择结构程序设计_进阶

    <C语言程序设计>实验报告 学 号 160809209 姓 名 李梦鑫 专业.班 计科16-2班 学    期 2016-2017 第1学期 指导教师 黄俊莲 吴喆 实验地点 C05 机 ...

  9. 160809209_李梦鑫_C语言程序设计实验2 选择结构程序设计

    实验2-1 输入3个数,并按由大到小的顺序输出. 实验要求: 编写一个C程序,输入3个数,并按由大到小的顺序输出. 源码:#include <stdio.h> int main() { i ...

随机推荐

  1. 论文解读(MPNN)Neural Message Passing for Quantum Chemistry

    论文标题:DEEP GRAPH INFOMAX 论文方向:  论文来源:ICML 2017 论文链接:https://arxiv.org/abs/1704.01212 论文代码: 1 介绍 本文的目标 ...

  2. C++ IDE或编辑器安装

    IDE介绍 上节课我们讲了C++编译器,可是没有好的编辑器,只用记事本打代码,这谁受得了.Linux vim至少还有代码高亮(即我作文里经常会出现的"彩色的代码"),记事本连高亮都 ...

  3. Proxypool代理池搭建

    个人博客:点我 前言 项目地址 : https://github.com/jhao104/proxy_pool 这个项目是github上一个大佬基于python爬虫制作的定时获取免费可用代理并入池的代 ...

  4. keras框架下的深度学习(一)手写体识别

    这个系列文章主要记录使用keras框架来搭建深度学习模型的学习过程,其中有一些自己的想法和体会,主要学习的书籍是:Deep Learning with Python,使用的IDE是pycharm. 在 ...

  5. Ysoserial Commons Collections7分析

    Ysoserial Commons Collections7分析 写在前面 CommonsCollections Gadget Chains CommonsCollection Version JDK ...

  6. SharkCTF2021 Classic_Crypto_king2

    crypto类题. 题面如下: 前面的代码给出了原理:后面的字符串第一行是print出的key,第二行是密文. 加密原理是,首先对table进行乱序处理,然后将明文flag按照(顺序table--&g ...

  7. cunda 常用命令,删除,创建,换源

    https://github.com/tensorflow/tensorflow/ conda create --name [虚拟环境名] python=3.7 创建一个环境 conda activa ...

  8. [技术博客] 软工-Ruby on Rails 后端开发总结分享

    [技术博客] 软工-Ruby on Rails 后端开发总结分享 在这次软件编写中,我们的后端使用了Ruby on Rails (RoR)框架. Rails框架是用Ruby编写的.这意味着当我们为Ru ...

  9. Vue 报错Error in render: “TypeError: Cannot read properties of null (reading ‘xxx’)” found in

    前端vue报错 [Vue warn]: Error in render: "TypeError: Cannot read properties of null (reading 'name' ...

  10. Spring Security Resource Server的使用

    Spring Security Resource Server的使用 一.背景 二.需求 三.分析 四.资源服务器认证流程 五.实现资源服务器 1.引入jar包 2.资源服务器配置 3.资源 六.测试 ...