我是怎么找到我的名字在哪里并且输出来的?然后我定义的那个字符串二维数组的大小是根据什么制定的!
研究一下ChatGPT给的sample示例
#include <stdio.h>
int main()
{
char text[] = "My name is John";
char stamp[100][100];
int i, j;
int len = strlen(text);
int col = len + 4;
int row = 4;
// 将字符串中的每一个字符放到电子印章中
for (i = 0; i < row; i++) {
for (j = 0; j < col; j++) {
if (i == 0 || i == row - 1) {
if (j == 0 || j == col - 1)
stamp[i][j] = '#';
else
stamp[i][j] = '-';
} else {
if (j == 0 || j == col - 1)
stamp[i][j] = '|';
else
stamp[i][j] = text[j - 2];
}
}
}
// 输出电子印章
for (i = 0; i < row; i++) {
for (j = 0; j < col; j++) {
printf("%c", stamp[i][j]);
}
printf("\n");
}
return 0;
}
//输出:
#-My name is John-|
| |
| |
#----------------#