Write the function prints using the while repeat structure instead of for. If necessary I can edit and insert all the code.
void imprime(Ccc *p)
{
Ccc *r;
for (r = p; r!=NULL; r = r->proximo)
printf("%c",r->caracter);
}
Full
#include <stdio.h>
#include <stdlib.h>
typedef struct ccc {
char caracter;
struct ccc *proximo;
} Ccc;
void imprime(Ccc *p)
{
Ccc *r;
for (r = p; r!=NULL; r = r->proximo)
printf("%c",r->caracter);
}
void liberar_memoria(Ccc *p)
{
Ccc *q, *r;
q = p;
while (q!=NULL) {
r = q->proximo;
free(q);
q = r;
}
}
main()
{
Ccc *p1, *p2, *p3;
p1=(Ccc *)malloc(sizeof(Ccc));
p2=(Ccc *)malloc(sizeof(Ccc));
p3=(Ccc *)malloc(sizeof(Ccc));
if ((p1==NULL)||(p2==NULL)||(p3==NULL))
return;
p1->caracter='A';
p1->proximo=p2;
p2->caracter='L';
p2->proximo=p3;
p3->caracter='O';
p3->proximo=NULL;
imprime(p1);
liberar_memoria(p1);
}