C:我不断收到错误消息:预期表达式

标签 c compiler-errors syntax-error function-calls

在我的函数中谈论变量时,我的代码中不断出现五个错误:错误:预期表达式。我查看了这个网站和其他地方,但找不到问题所在。

代码如下:

#include <stdio.h>

#define TRUE 1
#define FALSE 0

void separate_digits (long int n);
void print_array ( int a[10] );
int digits_different ( int a[10] );
int divisible ( int a[10], int n );

int main ()
{
    long int n;

printf("Enter a positive integer or 0 (zero) to end:");
scanf("%ld\n", &n);

while ( n != 0)
{
    if (n < 0)
    {
        printf("Wrong input\n");
    }

    else
    {
        separate_digits (long int n);
    }

    printf("Enter a positive integer or 0 (zero) to end:");
    scanf("%ld\n", &n);
}

printf("*** Program Terminated ***\n");

}

void separate_digits (long int n)
{
    int a[10] = {0};
    int digit;
    int num = n;

while ( num > 0)
{
    digit = num % 10;

    ++a[digit];

    num = num / 10;
}

print_array ( int a[10] );

if ( a[0] != 0 )
{
    printf("Wrong input for the second part.\n");
    printf("Input should not contain zero.\n");
}

else if ( digits_different ( int a[10] ) == FALSE )
{
    printf("Wrong input for the second part.\n");
    printf("Input should not contain each digit more than once.\n");
}

else if ( divisible ( int a[10], int n ) == FALSE )
{
    printf("%1ld is not divisible by its digits.\n", n);
}

else
{
    printf("%1ld is divisible by its digits.\n", n);
   }
}

void print_array ( int a[10] )
{
int i;

printf("\n\n\n");
printf("Digits:         0   1   2   3   4   5   6   7   8   9\n");
printf("Occurrences:    ");

for (i = 0; i < 10; i++)
{
    printf("a[i]   ");
}
}

 int digits_different ( int a[10] )
{
int i;

for (i = 0; i < 10; i++)
{
    if (a[i] > 1)
        return FALSE;

    else
        return TRUE;
}
}

int divisible ( int a[10], int n )
{
int i;
int num;

for (i = 0; i < 10; i++)
{
    if (a[i] == 0)
        continue;
    else if (num % i != 0)
        return FALSE;
}

return TRUE;
}

这是我不断收到的错误:

Lab_Assignment_6_Sarah_H.c:27:21: error: expected expression
         separate_digits (long int n);
                                     ^
Lab_Assignment_6_Sarah_H.c:53:16: error: expected expression
         print_array ( int a[10] );
                  ^
Lab_Assignment_6_Sarah_H.c:61:31: error: expected expression
        else if ( digits_different ( int a[10] ) == FALSE )
                                 ^
Lab_Assignment_6_Sarah_H.c:67:24: error: expected expression
        else if ( divisible ( int a[10], int n ) == FALSE )
                          ^
Lab_Assignment_6_Sarah_H.c:67:35: error: expected expression
        else if ( divisible ( int a[10], int n ) == FALSE )

最佳答案

当您实际将变量传递给函数时,您不应该在变量前加上类型名称。

只有在这些函数的声明中才需要,正如您在代码顶部附近所做的那样。

关于C:我不断收到错误消息:预期表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40384026/

相关文章:

php - PHP解析/语法错误;以及如何解决它们

c - 尝试使用 gcc 编译 c 文件时出现错误

C:使用单个#define 传递两个逗号分隔的值

javascript - 为什么 (x += x += 1) 在 C 和 Javascript 中的计算方式不同?

c++ - htmlcxx0.84编译错误

error-handling - 如何在yyerror中获取当前 token ?

c - 从套接字读取时如何处理阻塞 read() 调用?

C++ 错误 : expected identifier before ‘int’

c++ - 在 ‘;’ token 之前预期为 ‘{’

jquery - 获取未捕获的语法错误: Unexpected Token ':'