fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. // your code goes here
  5. return 0;
  6. }
  7.  
Success #stdin #stdout 0s 5308KB
stdin

/*
#include <errno.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdnoreturn.h>
#include <time.h>
#include <unistd.h>

#define UNUSED(x) (void)(x)
#define _GNU_SOURCE

#define CHK(op)                                                                \
    do {                                                                       \
        if ((op) == -1)                                                        \
            raler (1, #op);                                                    \
    } while (0)

noreturn void raler (int syserr, const char *msg, ...)
{
    va_list ap;

    va_start (ap, msg);
    vfprintf (stderr, msg, ap);
    fprintf (stderr, "\n");
    va_end (ap);

    if (syserr == 1)
        perror ("");

    exit (EXIT_FAILURE);
}

void tri_a_bulles (int *tab, int size)
{
    for (int i = size - 1; i > 0; i--) {
        for (int j = 0; j < i; j++) {
            if (tab [j + 1] < tab [j]) {
                // Swap the elements
                int temp = tab [j];
                tab [j] = tab [j + 1];
                tab [j + 1] = temp;
            }
        }
    }
}

void sigalrm_handler (int signo)
{
    (void)signo; // Explicitly indicate that the parameter is not used
    printf ("working\n");
    alarm (1); // Schedule the next alarm
}

int main (int argc, char *argv [])
{
    if (argc != 2) {
        fprintf (stderr, "Usage: %s <size>\n", argv [0]);
        exit (EXIT_FAILURE);
    }

    int size = atoi (argv [1]);
    if (size <= 0) {
        fprintf (stderr, "Invalid size\n");
        exit (EXIT_FAILURE);
    }

    // Create and initialize the array
    int *array = (int *)malloc (size * sizeof (int));
    if (array == NULL)
        raler (1, "malloc failed");

    srand ((unsigned int)time (NULL));
    for (int i = 0; i < size; i++)
        array [i] = rand () % 1001;

    // Set up the SIGALRM handler
    struct sigaction sa;
    sa.sa_handler = sigalrm_handler;
    sa.sa_flags = 0;
    CHK (sigaction (SIGALRM, &sa, NULL));

    // Set the initial alarm
    alarm (1);

    // Sort the array using bubble sort
    tri_a_bulles (array, size);

    // Cancel the next SIGALRM
    alarm (0);

    // Print the sorted array
    for (int i = 0; i < size; i++)
        printf ("%d\n", array [i]);

    free (array);

    return 0;
}
*/
#include <errno.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdnoreturn.h>
#include <time.h>
#include <unistd.h>

#define UNUSED(x) (void)(x)

#define CHK(op)                                                                \
    do {                                                                       \
        if ((op) == -1)                                                        \
            raler (1, #op);                                                    \
    } while (0)

noreturn void raler (int syserr, const char *msg, ...)
{
    va_list ap;

    va_start (ap, msg);
    vfprintf (stderr, msg, ap);
    fprintf (stderr, "\n");
    va_end (ap);

    if (syserr == 1)
        perror ("");

    exit (EXIT_FAILURE);
}

void tri_a_bulles (int *tab, int size)
{
    for (int i = size - 1; i > 0; i--) {
        for (int j = 0; j < i; j++) {
            if (tab [j + 1] < tab [j]) {
                // Swap the elements
                int temp = tab [j];
                tab [j] = tab [j + 1];
                tab [j + 1] = temp;
            }
        }
    }
}

void sigalrm_handler (int signo)
{
    UNUSED (signo);
    printf ("working\n");
    alarm (1);
}

int main (int argc, char *argv [])
{
    if (argc != 2) {
        fprintf (stderr, "Usage: %s <size>\n", argv [0]);
        exit (EXIT_FAILURE);
    }

    int size = atoi (argv [1]);
    if (size <= 0) {
        fprintf (stderr, "Invalid size\n");
        exit (EXIT_FAILURE);
    }

    // Create and initialize the array
    int *array = (int *)malloc (size * sizeof (int));
    if (array == NULL)
        raler (1, "malloc failed");

    srand ((unsigned int)time (NULL));
    for (int i = 0; i < size; i++)
        array [i] = rand () % 1001;

    // Set up the SIGALRM handler
    struct sigaction sa;
    sa.sa_handler = sigalrm_handler;
    sa.sa_flags = 0;
    CHK (sigaction (SIGALRM, &sa, NULL));

    // Set the initial alarm
    alarm (1);

    // Sort the array using bubble sort
    tri_a_bulles (array, size);

    // Cancel the next SIGALRM
    alarm (0);

    // Print the sorted array
    for (int i = 0; i < size; i++)
        printf ("%d\n", array [i]);

    free (array);

    return 0;
}
stdout
Standard output is empty