商务英语计算机英语

c语言中puts的用法

本文已影响 1.77W人 

c语言中puts的用法的用法你知道吗?下面小编就跟你们详细介绍下c语言中puts的用法的用法,希望对你们有用。

ing-bottom: 66.56%;">c语言中puts的用法

  c语言中puts的用法的用法如下:

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 ('') with a newline character ('n') in the output stream.

当puts遇到时,会输出一个n,也就是换行。

所以puts( "" )时,因为字符串本身长度为0,所以第一个字符就是,puts会输出一个n,所以起到了换行的效果。

也就是说, puts( "" )跟puts( "" )是等效的,也等效於printf( "n" )

printf是通过系统的设备输出字符的,一般显示器是缺省输出设备

puts只能输出到显示器

使用设备可以使用重定向

比如你用printf显示的字符可以用重定向符输出到文件

myapp >

而用puts不可以

要高效的话cputs更高效而且功能更强大

猜你喜欢

热点阅读

最新文章

推荐阅读