错误C2143:语法错误:缺少';'之前')'

时间:2012-10-28 17:29:38

标签: c

//Program Written By: Andre Chitsaz-zadeh
//Program Written On: 10/7/12
//Program calculates book cost for multiple book orders. 
//Program written using multiple functions.

#include <stdio.h>
#define SIZE 5

void inputData();
void processingData(int costs[]);
int costs[5];

int main ()
{
    inputData();
    processingData(costs);
}

void inputData()
{
    int i = 0;
    printf( "\nPlease enter five products costs.\n" );
    while(i < 5)
    {
       scanf("%d", &costs[i]);
       i = i + 1;
    }
    printf("stuff");
    for (i = 0, i < 5, i++)
        printf("%d\n", costs[i]);
}

void processingData(int costs[])
{
     int i;
     for (i = 0; i < 4; ++i)
     {
          int j, min, temp;
          min = i;
          for (j = i+1; j < 5; ++j)
          {
               if (costs[j] < costs[min])
                    min = j;
          }

          temp = costs[i];
          costs[i] = costs[min];
          costs[min] = temp;
     }
}

它在撒谎......我没有错过任何一种分号。我已经在程序的这一点上停留了一段时间,似乎我错过了一些愚蠢的东西。我得到这个错误的唯一一次是当我丢失分号并且我已经多次彻底检查了我的程序...谢谢!

3 个答案:

答案 0 :(得分:11)

编译器不会说谎。

inputData函数中:

for (i = 0, i < 5, i++)

应该是:

for (i = 0; i < 5; i++)

奇怪的是,你在processingData函数中得到了for循环。

答案 1 :(得分:1)

尝试更改

中的for循环
void inputData()

{
    int i = 0;
    printf( "\nPlease enter five products costs.\n" );
    while(i < 5)
    {
    scanf("%d", &costs[i]);
    i = i + 1;

    }
    printf("stuff");
    for (i = 0, i < 5, i++)
        printf("%d\n", costs[i]);

    return;
}

使用以下for循环

for (i = 0; i < 5; i++)

答案 2 :(得分:1)

问题在于:

for (i = 0, i < 5, i++)

应该是

for (i = 0; i < 5; i++)