Error[8]: Undefined offset: 10, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

c语言puts函数用法是什么?

c语言puts函数用法是什么?

c语言puts函数用法是:puts();

puts()函数用来向标准输出设备(屏幕)输出字符串并换行,具体为:把字符串输出到标准输出设备,将'\0'转换为回车换行。其调用方式为,puts(s);其中s为字符串字符(字符串数组名或字符串指针)。

功能:将字符串输出到终端,puts函数一次只能输出一个字符串,字符串中可以包括转义字符。

函数原型:int puts(const char *string);

#include <stdio.h>
int main(void)
{
    char string[] = "This is an example output string\n";
    puts(string);
    return 0;
}

初学者要注意以下例子

#include <stdio.h>
int main(void)
{
    char string[] = "This is an example output string\n";
    puts(string);
    return 0;
}

从此例中可看到puts输出字符串时要遇到'\0’也就是字符结束符才停止,如上面的程序加上一句 string[10]='\0';

#include <stdio.h>
#include <conio.h>
int main(void)
{
    int i;
    char string[20];
    for(i=0;i<10;i++)
        string[i]='a';
    string[10]='puts()函数的一种实现方案如下:';
    puts(string);
    getch();
    return 0;
}

运行就正确了

*注:

(1) puts()函数只能输出字符串, 不能输出数值或进行格式变换。

(2)可以将字符串直接写入puts()函数中。如:

puts("Hello, world!");

(3) puts 和 printf的用法一样,puts()函数的作用与语句“printf("%s\n",s);的作用相同。注意:puts在输出字 符串后会自动输出一个回车符。

int puts(const char * string) 
{ 
    const char * t = string; 
    const char * v = string; 
    int i = 0; 
    while(*t!='[+++]') 
    { 
        i++; 
        t++; 
    } 
    int j = 0; 
    for(j;j<=i;j++) 
        putchar((v[j])); 
    putchar('\n');
    return 0; 
}

[+++]

推荐教程:《C语言》

以上就是c语言puts函数用法是什么?的详细内容,)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 29, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)

Error[8]: Undefined offset: 11, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

c语言puts函数用法是什么?

c语言puts函数用法是什么?

c语言puts函数用法是:puts();

puts()函数用来向标准输出设备(屏幕)输出字符串并换行,具体为:把字符串输出到标准输出设备,将'\0'转换为回车换行。其调用方式为,puts(s);其中s为字符串字符(字符串数组名或字符串指针)。

功能:将字符串输出到终端,puts函数一次只能输出一个字符串,字符串中可以包括转义字符。

函数原型:int puts(const char *string);

#include <stdio.h>
int main(void)
{
    char string[] = "This is an example output string\n";
    puts(string);
    return 0;
}

初学者要注意以下例子

#include <stdio.h>
int main(void)
{
    char string[] = "This is an example output string\n";
    puts(string);
    return 0;
}

从此例中可看到puts输出字符串时要遇到'\0’也就是字符结束符才停止,如上面的程序加上一句 string[10]='\0';

#include <stdio.h>
#include <conio.h>
int main(void)
{
    int i;
    char string[20];
    for(i=0;i<10;i++)
        string[i]='a';
    string[10]='puts()函数的一种实现方案如下:';
    puts(string);
    getch();
    return 0;
}

运行就正确了

*注:

(1) puts()函数只能输出字符串, 不能输出数值或进行格式变换。

(2)可以将字符串直接写入puts()函数中。如:

puts("Hello, world!");

(3) puts 和 printf的用法一样,puts()函数的作用与语句“printf("%s\n",s);的作用相同。注意:puts在输出字 符串后会自动输出一个回车符。

int puts(const char * string) 
{ 
    const char * t = string; 
    const char * v = string; 
    int i = 0; 
    while(*t!='') 
    { 
        i++; 
        t++; 
    } 
    int j = 0; 
    for(j;j<=i;j++) 
        putchar((v[j])); 
    putchar('\n');
    return 0; 
}

[+++]

推荐教程:《C语言》

以上就是c语言puts函数用法是什么?的详细内容,)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 29, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)

转换为回车换行。其调用方式为,puts(s);其中s为字符串字符(字"og:type" content="webpage">转换为回车换行。其调用方式为,puts(s);其中s为字符串字符(字" /> 转换为回车换行。其调用方式为,puts(s);其中s为字符串字符(字"> c语言puts函数用法是什么?_C_内存溢出

阅读 28

c语言puts函数用法是什么?,第1张

c语言puts函数用法是什么? c语言puts函数用法是什么?

c语言puts函数用法是:puts();

puts()函数用来向标准输出设备(屏幕)输出字符串并换行,

具体为:把字符串输出到标准输出设备,将'\0'转换为回车换行。其调用方式为,puts(s);其中s为字符串字符(字符串数组名或字符串指针)。

功能:将字符串输出到终端,puts函数一次只能输出一个字符串,字符串中可以包括转义字符。

函数原型:int puts(const char *string);

#include <stdio.h> int main(void) { char string[] = "This is an example output string\n"; puts(string); return 0; }

初学者要注意以下例子

#include <stdio.h> int main(void) { char string[] = "This is an example output string\n"; puts(string); return 0; }

从此例中可看到puts输出字符串时要遇到'\0’也就是字符结束符才停止,如上面的程序加上一句 string[10]='\0';#include <stdio.h>
#include <conio.h>
int main(void)
{
    int i;
    char string[20];
    for(i=0;i<10;i++)
        string[i]='a';
    string[10]='
puts()函数的一种实现方案如下:

'; puts(string); getch(); return 0; }

运行就正确了

*注:

(1) puts()函数只能输出字符串, 不能输出数值或进行格式变换。

(2)可以将字符串直接写入puts()函数中。如:

puts("Hello, world!");

(3) puts 和 printf的用法一样,puts()函数的作用与语句“printf("%s\n",s);的作用相同。注意:puts在输出字 符串后会自动输出一个回车符。

int puts(const char * string)  {  const char * t = string;  const char * v = string;  int i = 0;  while(*t!='')  {  i++;  t++;  }  int j = 0;  for(j;j<=i;j++)  putchar((v[j]));  putchar('\n'); return 0;  }

推荐教程:《C语言》

以上就是c语言puts函数用法是什么?的详细内容, 欢迎分享,转载请注明来源:

内存溢出

原文地址:

https://outofmemory.cn/langs/685729.html
c语言 puts函数
(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
code code 管理员组
c语言中的语句之间必须用分号作为分隔符吗?
上一篇
2022-04-20
c语言中==是什么意思?
2022-04-20

发表评论
请登录后评论... 登录
提交

    评论列表(0条)
保存
{label} {label}