c-数组下标不是整数



复制字符串的代码

#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]='';
    //printing the new string
    puts[to];

}

为什么编译器show数组下标在这个语句中不是一个整数?

放入[到];

但为什么这没有显示错误呢?

看跌期权;

它应该是'puts(to);'我觉得你把数组和函数搞混了[]"表示数组,"()"表示函数调用。

Chnage

puts[to]; to puts(to); 

put[to]表示您正在声明一个数组。

  • []用于数组大小声明。

  • ()用于函数调用。

最新更新