| PLEX86 | ||
|
creat 1176
Charlie Gibbs ... snip ... creat 1177 Well, there's also the organ that could be used as a study in human-interface design. Long but steep learning... You should have had the following around :-) Take 1 from column A, and 1 from column B ... * Routines to reverse a file, char by char. *-* by C.B. Falconer, 19 Dec. 2001 *-* Released to public domain. Attribution appreciated * * Known bugs - A file without an initial empty line *-* will have one added. * #define MAXLN 256 typedef struct line { char *ln; struct line *next; } line, *lineptr; * ======================================= *-* reverse string in place. Return length *sizet revstring(char *string) { char *last, temp; sizet lgh; lgh = strlen(string); last = string + lgh; * points to '-0' * temp = *string; *string++ = *last; *last = temp; } return lgh; }* revstring * * ========================= *-* Reverse file, end to end *int main(void) { char bufferMAXLN; lineptr p, last; sizet lgh; p = last = NULL; while (fgets(buffer, MAXLN, stdin)) { lgh = revstring(buffer); if (p = malloc(sizeof (line))) { last = p; } else { free(p); break; } } else break; } p = NULL; while (last) { free(p); p = last; } fputc('-n', stdout); free(p); return 0; }* main * -- "If you want to post a followup via groups.google.com, don't use the broken "Reply" link at the bottom of the article. Click on "show options" at the top of the article, then click on the "Reply" at the bottom of the article headers." - Keith Thompson
|
||||||||