0
点赞
收藏
分享

微信扫一扫

字符串 - 7. 输出字符串 (10 分)C语言标准函数库中 printf 函数和 puts 函数都可以输出字符串,但各有优点和缺点。我们综合两者的优点,设计一个函数来输出字符串。

书坊尚 2022-04-21 阅读 82
c语言

C语言标准函数库中 printf 函数和 puts 函数都可以输出字符串,但各有优点和缺点。我们综合两者的优点,设计一个函数来输出字符串。

函数原型

 
int PutStr(const char *str);

说明:str 为字符串的起始地址。函数将输出 str 所指示的字符串,不自动换行。函数值为输出字符的数目。

裁判程序

#include <stdio.h>

int PutStr(const char *str);

int main()
{
    char a[1024];
    int n;
    gets(a);
    n = PutStr(a);
    printf("(%d)\n", n);
    return 0;
}

/* 你提交的代码将被嵌在这里 */

输入样例

John

输出样例

John(4)

 

int PutStr(const char *str)
{
    printf("%s",str);
    int number=0;
    while(*str)
    {
        number++;
        str++;
    }
   
    return number;
}
举报

相关推荐

0 条评论