复制字符串的代码
#include<stdio.h>
#include<string.h>
int main()
{
char from[100]="we are the people",to[100];
int i,count=0;
puts(from);
//copying string
for(i=0;from[i];i++)
{
to[i]=from[i];
}
to[i]='\0';
//printing the new string
puts[to];
}
为什么编译器显示数组下标在这个语句中不是一个整数?
放[到];
但为什么这不显示错误?
放[从];
答案 0 :(得分:2)
它应该是'put(to);&#39;我认为你混淆了数组和功能。 &#39; []&#39;用于数组和&#39;()&#39;用于函数调用。
答案 1 :(得分:2)
Chnage
puts[to]; to puts(to);
puts [to]表示您正在声明一个数组。
[]用于数组大小声明。
()用于函数调用。