错误代码:
#include<stdio.h>
#include<string.h>
int main()
{
int n;
scanf("%d",&n);
char c[50][50];
int i,j;
for(i=0;i<n;i++){
for(j=0;j<n;j++){
strcpy(c[i][j],"hello");
}
}
for(i=0;i<n;i++){
for(j=0;j<n;j++){
printf("%s ",c[i][j]);
}
}
return 0;
}
不能直接使用strcpy
函数将字符串复制到二维字符数组的特定元素中。strcpy
函数用于将一个字符串复制到另一个字符串中,而二维字符数组中的元素是字符,而不是字符串。
正确代码:
#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
int i,j;
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
printf("hello ");
}
printf("\n");
}
return 0;
}