#include <stdio.h> struct alf { char lt; struct alf *next; }ar[27]; int main() { struct alf *list_p; char ch, *str, *ar_p[12]; short indx; ch = 97; str = "hello world"; for(indx = 0; indx <= 25; indx++, ch++) { ar[indx].lt = ch; ar[indx].next = &ar[indx+1]; } ar[26].lt = ' '; ar[26].next = (void *)0; for(indx = 0; *str != 0; str++) { list_p = ar; /* back 'a' */ while(list_p) { if(list_p->lt == *str) ar_p[indx++] = &list_p->lt; list_p = list_p->next; } } *ar_p[11] = '\0'; for(indx = 0; *ar_p[indx] != '\0'; indx++) printf("%c", *ar_p[indx]); putchar('\n'); return(0); }
OUTPUT:
hello world
I'm updating this becase I realy like it.. (dec 10)
struct alf is a linked list with alphabet letters, and one space
(becouse hello world have a space :P)
So.. I got an array that have pointers pointing to the right members
of the list.. I don't copy the chars... I print it from where they are
I have linked an array... so stupid!
ResponderExcluir