2014-11-03 51 views
-4

代碼數組下標是不可複製的字符串的integar

#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]; 


} 

爲什麼編譯器顯示數組下標不是本聲明的integar?

puts [to];

但爲什麼這不顯示錯誤?

puts [from];

+0

這些都是錯誤。你應該寫'puts(to);' – 2014-11-03 02:41:59

+0

thanx我沒有注意到 – 2014-11-03 02:57:33

回答

2

它應該是'puts(to);'我認爲你混合了數組和函數。 '[]'用於數組,'()'用於函數調用。

2

Chnage

puts[to]; to puts(to); 

看跌期權[到]意味着你正在聲明的陣列。

  • []用於數組大小聲明。

  • ()用於函數調用。

相關問題