#include <stdio.h>
#include <pthread.h>
void* stampa_numeri_e_carattere(void* arg) {
void** args = (void**) arg; // Cast dell'argomento a un array di void*
int max = *(int*) args[0]; // Primo parametro: numero massimo
char simbolo = *(char*) args[1]; // Secondo parametro: carattere
for (int i = 1; i <= max; i++) {
printf("%d %c\n", i
, simbolo
); }
return NULL;
}
int main() {
pthread_t thread;
int max = 5; // Numero massimo da stampare
char simbolo = '*'; // Carattere da stampare
// Creazione dell'array di parametri
void* args[2];
args[0] = &max;
args[1] = &simbolo;
// Creazione del thread con passaggio di parametri
pthread_create(&thread, NULL, stampa_numeri_e_carattere, (void*) args);
// Attesa della terminazione del thread
pthread_join(thread, NULL);
printf("Programma terminato.\n"); return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxwdGhyZWFkLmg+Cgp2b2lkKiBzdGFtcGFfbnVtZXJpX2VfY2FyYXR0ZXJlKHZvaWQqIGFyZykgewogICAgdm9pZCoqIGFyZ3MgPSAodm9pZCoqKSBhcmc7IC8vIENhc3QgZGVsbCdhcmdvbWVudG8gYSB1biBhcnJheSBkaSB2b2lkKgogICAgaW50IG1heCA9ICooaW50KikgYXJnc1swXTsgIC8vIFByaW1vIHBhcmFtZXRybzogbnVtZXJvIG1hc3NpbW8KICAgIGNoYXIgc2ltYm9sbyA9ICooY2hhciopIGFyZ3NbMV07IC8vIFNlY29uZG8gcGFyYW1ldHJvOiBjYXJhdHRlcmUKCiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBtYXg7IGkrKykgewogICAgICAgIHByaW50ZigiJWQgJWNcbiIsIGksIHNpbWJvbG8pOwogICAgfQogICAgcmV0dXJuIE5VTEw7Cn0KCmludCBtYWluKCkgewogICAgcHRocmVhZF90IHRocmVhZDsKCiAgICBpbnQgbWF4ID0gNTsgICAgICAgIC8vIE51bWVybyBtYXNzaW1vIGRhIHN0YW1wYXJlCiAgICBjaGFyIHNpbWJvbG8gPSAnKic7IC8vIENhcmF0dGVyZSBkYSB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