C 错误:在‘之前应为表达式;int’;

C 错误:在‘之前应为表达式;int’;,c,C,这是我参加的一个大学课程的一个项目,该课程用C语言授课。我对C语言和一般编程都很陌生,有时我会遇到很多错误 我对这些错误有意见 level1.c:23: error: expected expression before ‘int’ 及 我花了很长时间尝试不同的方法来修复错误,但我无法解决它。 这是它的源代码 int main(int argc,char **argv) { int i; int count; char *dictionary; if (arg

这是我参加的一个大学课程的一个项目,该课程用C语言授课。我对C语言和一般编程都很陌生,有时我会遇到很多错误

我对这些错误有意见

level1.c:23: error: expected expression before ‘int’

我花了很长时间尝试不同的方法来修复错误,但我无法解决它。 这是它的源代码

int main(int argc,char **argv)
{
    int i;
    int count;
    char *dictionary;

    if (argc != 3)
    {
        printf("need two arguments!\n");
        exit(-1);
    }
    count = readALLTokens(argv[1]);
    printf("there are %d tokens and strings\n",count);

    dictionary = memalloc(int *count);    /* ERROR ON THIS LINE */

    arrayfill(argv[1]);

    printf("THE DICIONARY...\n");
    for (i = 0; i < count; ++i)
    {
        printf("%d\n",dictionary[i]);
    }

    return 0;
}
到目前为止的想法是,它应该读取字典文件,创建一个数组并为其分配适当的内存量,然后将字典文件读入数组,以便可以使用它与另一个文件进行比较,并使用字典文件中的字符串“翻译”它。
我不确定我的代码有多少是正确的,但到目前为止,它似乎能够完成我需要的任务。

第一件事:您的代码输出大量警告。其中许多都与这样一个事实有关,即在调用函数之前,没有函数的原型。你应该认真地解决这个问题

其次:要传递指向变量的指针,请使用
&
运算符。例如:

dictionary = memalloc(&count);

发布您的确切代码-我想可能您为了简洁起见省略了一些#include行,但这些行对本期非常重要。您可以(用英语)描述一下您期望“dictionary=memalloc(int*count);”做什么;还有“memalloc”应该做什么?我不记得“dictionary=memalloc(int*count);”应该做什么。几天前,当我开始这个项目的时候,我写了这篇文章。现在我看着它,我不完全确定我认为它首先会做什么。此时我需要做的是为数组“a[]”分配内存,以便在arrayfill函数中用dictionary中的标记填充它。另外,我确实有头文件来引用所有这些函数。我之前忘了提到这一点。另外,我在我的所有.c文件中添加了#include#include#include#include#include,希望它能覆盖所有没有这些原因的问题。问题远不止于此,
memalloc
函数不需要更改
count
,但它完全被破坏了
int readALLTokens(char *);
int count = 0;

int readALLTokens(char *dictionary)
{
    FILE *fp;
    char *token;

    fp = fopen(dictionary,"r");
    if (fp == 0)
    {
        fprintf(stderr,"file %s could not be opened for reading\n",dictionary);
        exit(1);
    }
    token = readToken(fp);
    while (!feof(fp))
    {
        printf("%s\n",token);
        ++count;
        free(token);
        token = readToken(fp);
    }
    fclose(fp);

    return count;
}

char *a[10];

int memalloc(int *count)
{
    *a = malloc(sizeof(count));
    return 0;
}

void arrayfill(char *dictionary)
{
    FILE *fp;

    fp = fopen(dictionary,"r");
    int t = 0;
    char *token;

    token = readToken(fp);
    while (!feof(fp))
    {
        fscanf(fp,"%s",*(a + t));
        ++t;
        free(token);
        token = readToken(fp);
    }
    fclose(fp);

    return;
}
dictionary = memalloc(&count);