#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
typedef int bool;
enum { false, true };
// elemento da lista
typedef struct estr {
char letra;
struct estr *prox;
} NO;
typedef struct {
NO *inicio;
} LISTA;
void inicializarLista(LISTA *l) {
l->inicio = NULL;
}
void criarLista(LISTA *l, char plvr[]) {
NO *ult = NULL;
for (int i
= 0; i
< strlen(plvr
); i
++) { NO
*novo
= (NO
*) malloc(sizeof(NO
)); novo->letra = plvr[i];
novo->prox = NULL;
if (ult) {
ult->prox = novo;
} else {
l->inicio = novo;
}
ult = novo;
}
}
void imprimirLista(LISTA l) {
NO *p = l.inicio;
while(p) {
p = p->prox;
}
}
int main() {
LISTA l;
inicializarLista(&l);
char palavra[] = "caio";
//fgets(palavra, 3, stdin);
criarLista(&l, palavra);
imprimirLista(l);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPG1hbGxvYy5oPgojaW5jbHVkZSA8c3RyaW5nLmg+Cgp0eXBlZGVmIGludCBib29sOwplbnVtIHsgZmFsc2UsIHRydWUgfTsKCi8vIGVsZW1lbnRvIGRhIGxpc3RhCnR5cGVkZWYgc3RydWN0IGVzdHIgewogICAgY2hhciBsZXRyYTsKICAgIHN0cnVjdCBlc3RyICpwcm94Owp9IE5POwoKdHlwZWRlZiBzdHJ1Y3QgewogICAgTk8gKmluaWNpbzsKfSBMSVNUQTsKCnZvaWQgaW5pY2lhbGl6YXJMaXN0YShMSVNUQSAqbCkgewogICAgbC0+aW5pY2lvID0gTlVMTDsKfQoKdm9pZCBjcmlhckxpc3RhKExJU1RBICpsLCBjaGFyIHBsdnJbXSkgewogICAgTk8gKnVsdCA9IE5VTEw7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IHN0cmxlbihwbHZyKTsgaSsrKSB7CiAgICAgICAgTk8gKm5vdm8gPSAoTk8gKikgbWFsbG9jKHNpemVvZihOTykpOwogICAgICAgIG5vdm8tPmxldHJhID0gcGx2cltpXTsKICAgICAgICBub3ZvLT5wcm94ID0gTlVMTDsKICAgICAgICBpZiAodWx0KSB7CiAgICAgICAgICAgIHVsdC0+cHJveCA9IG5vdm87CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgbC0+aW5pY2lvID0gbm92bzsKICAgICAgICB9CiAgICAgICAgdWx0ID0gbm92bzsKICAgIH0KfQoKdm9pZCBpbXByaW1pckxpc3RhKExJU1RBIGwpIHsKICAgIE5PICpwID0gbC5pbmljaW87CiAgICB3aGlsZShwKSB7CiAgICAgICAgcHJpbnRmKCIlYyIsIHAtPmxldHJhKTsKICAgICAgICBwID0gcC0+cHJveDsKICAgIH0KfQoKaW50IG1haW4oKSB7CiAgICBMSVNUQSBsOwogICAgaW5pY2lhbGl6YXJMaXN0YSgmbCk7CiAgICBjaGFyIHBhbGF2cmFbXSA9ICJjYWlvIjsKICAgIC8vZmdldHMocGFsYXZyYSwgMywgc3RkaW4pOwogICAgY3JpYXJMaXN0YSgmbCwgcGFsYXZyYSk7CiAgICBpbXByaW1pckxpc3RhKGwpOwoKICAgIHJldHVybiAwOwp9