home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!caen!destroyer!Tygra.Michigan.COM!jp
- From: jp@tygra.Michigan.COM (John Palmer)
- Subject: This will work under unix now
- Organization: CAT-TALK Conferencing System
- Date: Tue, 5 Jan 1993 07:58:21 GMT
- Message-ID: <1993Jan5.075823.10230jp@tygra.Michigan.COM>
- Lines: 65
-
- Dug this out of the code that I saved from this group (and others).
- It wouldn't work under XENIX/UNIX as you cannot give both variable
- names and their types in the function definition (inside the '()'s)
- ---
- #include <stdio.h>
- #include <stdlib.h>
-
- char * strwrap(char *, int, int);
-
- main()
- {
- char answer[10], *t, *author = "-- David Russell Conrad", *text =
- "This is a test. This is only a test. If this were real text, it "
- "would say something useful, or at least interesting anyway. The "
- "quick brown fox jumps over the lazy dog. This is the end.";
- int w, o, i;
- char *modified_by = "-- Modified for UNIX by John Palmer";
-
- if ((t = malloc(strlen(text)+1)) == NULL) {
- puts("Insufficient memory.");
- exit(1);
- }
- while (1) {
- fprintf(stderr,"Enter width to wrap at, 0 to end:");
- fgets(answer, 10, stdin);
- w = atoi(answer);
- if (!w) exit(0);
- fprintf(stderr,"Enter orphan sensitivity (minimum number of chars on last line):");
- fgets(answer, 10, stdin);
- o = atoi(answer);
- puts("");
- for (i = 0; i < w; i++)
- putchar('.');
- puts("");
- strcpy(t, text);
- printf("%s\n", strwrap(t, w, o));
- for (i = 0; i < (w-strlen(author))/2; i++)
- putchar(' ');
- printf("%s\n\n", author);
- for (i = 0; i < (w-strlen(modified_by))/2; i++)
- putchar(' ');
- printf("%s\n\n", modified_by);
- }
- }
-
- char * strwrap(s, w, o)
- char *s;
- int w,o;
- {
- char *c = s, *end;
-
- if (w-o < o || strlen(s) < o) return NULL;
- end = s + strlen(s);
- for (c += w; c < end; c += w+1) {
- for (; *c != ' ' || *(c+1) == ' ' || end-c <= o; c--) if (c < s) return NULL;
- *c = '\n';
- }
-
- return s;
- }
- --
- Its most likely a | E-MAIL: jp@michigan.com CAT-TALK IS BACK as a FREE
- forgery, so save your | SYSTEM!! 313-882-2209 300-14400 V.32/V.32BIS/TurboPEP
- flames for someone | Anon-UUCP: System: tygra, Login: nuucp, no pw
- who cares :-> | Get file "/cat/pub/filelist" for a list of files.
-