1
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);
}
Complete
#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);
}
You understood what the
for
are you doing? Could you describe with words?– Woss
Yes, I will post the full code.
– Diego Roney
But the question I asked was "Could you describe in words what you understood about the function of
for
in that code", not "please post the full code", although possibly it will be better with the full code.– Woss