I am a beginner in C and was working on a program that can output the prime numbers within the range using Eratosthenes' sieve. However, the program does not output anything and is in a loop, I believe this has to do with the repetitive use of for statements in my code but also have no idea where I may be going wrong. I tried putting break statements with if statements but it seems like it does not work. Thank you in advance.
#include <stdio.h>
#include <math.h>
int sieve(int limit);
int main() {
    int maximum = 0;
    printf("Enter the limit of prime numbers:");
    scanf_s("%d", &maximum);
    sieve(maximum);
    return 0;
}
int sieve(int limit) {
    int array[100];
    int common = 2;;
    for (int i = 0; i <= limit; i++) {
        array[i] = i + 1;
    }
    for (;;) {
        for (int j = 0; j <= limit; j++) {
            if (array[j] % common == 0 && !(array[j] == common)) {
                array[j] = 0;
                array[0] = 0;
            }
        } 
        for (int k = 0; k <= limit; k++) {
            if (!(array[k] == 0) && !(common == array[k])) {
                common = array[k];
                break;
            }
        }
        if (common >= sqrt(limit))
            break;
    }
    for (int o = 0; o < limit; o++) {
        if (!(array[o] == 0)) {
            printf("%d  ", array[o]);
        }
    }
    return 0;
}
 
     
     
    