现在的位置: 首页 > 综合 > 正文

编译错误syntax error : missing ‘;’ before ‘type’

2013年09月14日 ⁄ 综合 ⁄ 共 909字 ⁄ 字号 评论关闭

有一个数组a[1000]存放0--1000;要求每隔二个数删掉一个数,到末尾时循环至开头继续进行,求最后一个被删掉的数的原始下标位置。
以7个数为例:
   {0,1,2,3,4,5,6,7} 0-->1-->2(删除)-->3-->4-->5(删除)-->6-->7-->0(删除),如此循环直到最后一个数被删除。

#include<stdio.h>

#define null 1000
int main()

     int i;
     int arr[1000];
     for(i = 0; i < 1000; i++)
     arr[i] = i;
     int j = 0 ;
     int count = 0;
 
     while(count < 999)
    {
         while(arr[j%1000] == null)
                j = (++j)%1000;
         j = (++j)%1000;

         while(arr[j%1000] == null)
               j = (++j)%1000;
         j = (++j)%1000;

        while(arr[j%1000] == null)
               j = (++j)%1000;
        arr[j] = null;
        ++count;
    }

    while(arr[j] == null)
          j = (++j)%1000;
     printf("j = %d", j);

      return 0;
}

用vc会出现一下错误

error C2143: syntax error : missing ';' before 'type'
error C2143: syntax error : missing ';' before 'type'
error C2065: 'count' : undeclared identifier
error C2065: 'j' : undeclared identifier
Error executing cl.exe.

t2.exe - 4 error(s), 0 warning(s)

找了好久才发现红色标记的变量定义,应该放在最前面。

而我用gcc编译却顺利通过。。。

抱歉!评论已关闭.