I'm solving a basic C problem on a site called UVa Online Judge, and I encounter an error which seems to related to compiler options.
ANSI C 5.3.0 - GNU C Compiler with options: -lm -lcrypt -O2 -pipe -ansi -DONLINE_JUDGE
The problem(with problem id as prefix) is UVa 100 3n+1 problem
as following. It can be compiled and run, without error, on Visual Studio 2019, the site reported "Compile Error" for it. The site will not show any error message, just Compile Error
in its bulletin.
#include <stdio.h>
int get_cycle_length(int n);
int main() {
int i, j;
int l, r;
int max;
int n;
int cycle_length;
char line[10000] = { 0 };
size_t line_len = sizeof(line), read_len = 0, pos = 0;
while (scanf(" %d%d", &i, &j) != EOF) {
l = i > j? j: i;
r = i > j? i: j;
max = -1;
for (n = l; n <= r; n++) {
cycle_length = get_cycle_length(n);
if (cycle_length > max)
max = cycle_length;
}
read_len = snprintf(line+pos, line_len-pos, "%d %d %d\n", i, j, max);
if (pos+read_len > line_len) {
printf("%.*s", (int)pos, line);
pos = 0;
}
pos += read_len;
// printf("%d %d %d\n", i, j, max);
}
printf("%.*s", (int)pos, line);
return 0;
}
int get_cycle_length(int n) {
int count = 0;
while (n != 1) {
count++;
n = n & 1? 3*n+1: n/2;
}
count++;
return count;
}
= { 0 }
, still got CE.//
comment with/* ... */
.