从0开始的练级路(六)——puts()函数/字符串末尾'\0'问题/未来

(1)puts()函数

  功能:具体是把字符串输出到屏幕上,将‘\0’(c/c++)(字符串末尾'\0')转换为回车换行。调用方式是:puts(str)。其中str是字符串数组名或者字符串指针。实际上,数组名就是指针。

  注:

(1)puts()只能输出字符串,不能输出数值或者进行格式转换,即不能要求输出格式增加空格、换行(指的是输出内容的中间进行换行)等要求;

(2)可以将字符串直接写入puts()。如:puts("hello world");

(3)包含在头文件<stdio.h>中。(和<csdio>是一个东西)

#include <stdio.h>
int main(){
    char str[]="hello world";
    puts(str); 
    return 0;
} 

....但是貌似很容易出错所以不推荐使用puts()和gets()...

(2)大草ISBN号码

  因为不注意i<=12而写的i<12导致查错50分钟得我是屑

  一定要注意细枝末节哦哦哦哦哦哦哦!!!

扫描二维码关注公众号,回复: 9849451 查看本文章
#include"bits/stdc++.h"
using namespace std;
int main()
{
    char a[14],mod[12]="0123456789X";
    for(int i=0; i<=12; i++)
    {
        cin>>a[i];
    }
    int i,j=1,t=0;
    for(i=0; i<12; i++)
    {
        if(a[i]=='-') continue;
        t+=(a[i]-'0')*j++;
    }
    if(mod[t%11]==a[12])
        cout<<"Right";
    else
    {
        a[12]=mod[t%11];

        for(int i=0; i<13; i++)
        {
            cout<<a[i];
        }
    }
    return 0;
}

(3)未来

  我是未来的你,听我说!请你一定要天天向上,努力提升自己呀!

猜你喜欢

转载自www.cnblogs.com/Ricardohff/p/12501453.html