This is correct code for C++, not for C, because when using C compiler, only forward var declarations are permited
{
int N = 0;
int* AA = NULL;
// ...
AA = (int*)malloc(..);
// etc.
}
I receive this kind of errors again...
Compilation errors.
------------------
311e64be-7d0c-42db-86d6-9276eb18480e(8) : error C2143: syntax error : missing ';' before 'type'
311e64be-7d0c-42db-86d6-9276eb18480e(9) : error C2065: 'AA' : undeclared identifier
311e64be-7d0c-42db-86d6-9276eb18480e(9) : warning C4047: '=' : 'int' differs in levels of indirection from 'int *'
311e64be-7d0c-42db-86d6-9276eb18480e(20) : error C2065: 'AA' : undeclared identifier
311e64be-7d0c-42db-86d6-9276eb18480e(20) : error C2109: subscript requires array or pointer type
311e64be-7d0c-42db-86d6-9276eb18480e(25) : error C2065: 'AA' : undeclared identifier
311e64be-7d0c-42db-86d6-9276eb18480e(25) : error C2109: subscript requires array or pointer type
311e64be-7d0c-42db-86d6-9276eb18480e(31) : error C2065: 'AA' : undeclared identifier
311e64be-7d0c-42db-86d6-9276eb18480e(31) : error C2109: subscript requires array or pointer type
311e64be-7d0c-42db-86d6-9276eb18480e(33) : error C2065: 'AA' : undeclared identifier
311e64be-7d0c-42db-86d6-9276eb18480e(33) : warning C4022: 'free' : pointer mismatch for actual parameter 1
------------------
Full code
------------------
#include <stdio.h>
#include <malloc.h>
int main()
{
int total_zero, count_zero, i, N, K, s;
scanf("%d", &N);
int* AA = NULL;
AA = (int*)malloc(N*sizeof(int));
s = 0;
for( ; N > 0; N--){
scanf("%d", &K);
total_zero = count_zero = i = 0;
while( 1 ){
i++;
if(total_zero == count_zero){
count_zero = 0;
total_zero++;
if(i == K){
AA[s++] = 1;
break;
}
}
if(i == K){
AA[s++] = 0;
break;
}
count_zero++;
}
}
for(i = 0; i < s; i++) printf("%d ", AA[i]);
fputc('\n', stdout);
free(AA);
return 0;
}
------------------
error C2143: syntax error : missing ';' before 'type'
It is very strange.