2013-12-19 44 views
-2

我的程序不起作用。 我的問題是如何正確定義我的函數原型? 另外,函數調用中是否有錯誤? 請幫幫我!如何正確定義我的函數原型?

這裏是我的代碼:

#include <stdio.h> 
#include <string.h> 
#include <ctype.h> 
void copystring(char m[][],char temp[]); 
int main() 
{ 
    char temp[10000]; 
    char m[10000][10000]; 
    gets(temp); 
    copystring(m,temp); 
    printf("%s\n",m[0]); 
    printf("%s\n",m[1]);    
    return 0; 
} 

void copystring(char m[][],char temp[]) 
{ 
    int i=0; 
    int j=0; 
    int k; 
    for (k=0;k<(strlen(temp));k++) 
    { 
     if (temp[k]!=',') 
     { 
      m[j][i++]=temp[k]; 
     } 
     else 
     { 
      m[j][i]='\0'; 
      j++; 
      i=0; 
     } 
    } 
} 
+4

我強烈地認爲'char m [10000] [10000];'會引發堆棧溢出。 – alk

+0

這裏有什麼問題? – Chinna

+0

'void copystring(char m [] [10000],char temp []);'顯示完整,但最左側的例外 – BLUEPIXY

回答

2

最快的 「修復」 將做到這一點:

void copystring(char m[][10000],char temp[]); 

但是你的100MB陣列的提防!

1

假設C99或稍後更改copystring()的簽名是:

void copystring(size_t n, char m[n][n],char temp[n]); 

,並調用它像這樣:

copystring(10000, m, temp); 

不要使用

gets(temp) 

但使用

fgets(temp, 10000, stdin); 

後者照顧不溢出temp

+0

C中是否有可變長度數組? –

+0

@BitFiddlingCodeMonkey:是的,從C99開始就有。 – alk