如何正确定义我的函数原型?

时间:2013-12-19 10:34:30

标签: c function prototype

我的程序不起作用。 我的问题是如何正确定义我的函数原型? 此外,函数调用中是否有任何错误? 请帮我!

这是我的代码:

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

2 个答案:

答案 0 :(得分:2)

最快的“修复”就是这样做:

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

但要注意你的100MB阵列!!

答案 1 :(得分: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

相关问题