描述
C库函数 int puts(const char *str) 会将字符串写入到标准输出,但不包括null字符。会在字符串末尾自动加换行符。
声明
下面是 puts() 函数的声明:
int puts(const char *str)
参数
-
str -- 要写入到stdout的C字符串
返回值
如果成功,返回一个非负整数。出现错误,返回EOF。
示例
下面是puts()函数示例:
#include <stdio.h> #include <string.h> int main() { char str1[15]; char str2[15]; strcpy(str1, "tutorialspoint"); strcpy(str2, "compileonline"); puts(str1); puts(str2); return(0); }
对上面示例编译并运行会得到如下结果:
tutorialspoint compileonline