指针数组打印字符数组的问题

问题遇到的现象和发生背景

声明了一个字符数组,想用指针数组把字符数组打印出来,不知道为什么出现有乱码(虽然除开乱码后是理想的结果),麻烦各位帮我指正一下

用代码块功能插入代码,请勿粘贴截图
#include 
#include 
#include 
int main()
{
    char buffer[12][12];
    char *ptr[12];
    int a,b;
    for (a=0;a<12;a++)
    {
        for (b=0;b<12;b++)
        {
            buffer[a][b]='x';
        }
        ptr[a]=buffer[a];
        puts(ptr[a]);
    }
    
    return 0;
}


运行结果及报错内容

img

输出字符串时,字符数组结尾一定要有字符串结束符,而你没有

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    char buffer[12][13] = {0};
    char *ptr[12];
    int a,b;
    for (a=0;a<12;a++)
    {
        for (b=0;b<12;b++)
        {
            buffer[a][b]='x';
        }
        ptr[a]=buffer[a];
        puts(ptr[a]);
    }
    
    return 0;
}