home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19239 < prev    next >
Encoding:
Text File  |  1993-01-05  |  2.2 KB  |  75 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!caen!destroyer!Tygra.Michigan.COM!jp
  3. From: jp@tygra.Michigan.COM (John Palmer)
  4. Subject: This will work under unix now
  5. Organization: CAT-TALK Conferencing System
  6. Date: Tue, 5 Jan 1993 07:58:21 GMT
  7. Message-ID: <1993Jan5.075823.10230jp@tygra.Michigan.COM>
  8. Lines: 65
  9.  
  10. Dug this out of the code that I saved from this group (and others).
  11. It wouldn't work under XENIX/UNIX as you cannot give both variable
  12. names and their types in the function definition (inside the '()'s)
  13. ---
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16.  
  17. char * strwrap(char *, int, int);
  18.  
  19. main()
  20. {
  21.   char answer[10], *t, *author = "-- David Russell Conrad", *text =
  22. "This is a test.  This is only a test.  If this were real text, it "
  23. "would say something useful, or at least interesting anyway.  The "
  24. "quick brown fox jumps over the lazy dog.  This is the end.";
  25.   int w, o, i;
  26.   char *modified_by = "-- Modified for UNIX by John Palmer";
  27.  
  28.   if ((t = malloc(strlen(text)+1)) == NULL) {
  29.     puts("Insufficient memory.");
  30.     exit(1);
  31.   }
  32.   while (1) {
  33.     fprintf(stderr,"Enter width to wrap at, 0 to end:");
  34.     fgets(answer, 10, stdin);
  35.     w = atoi(answer);
  36.     if (!w) exit(0);
  37.     fprintf(stderr,"Enter orphan sensitivity (minimum number of chars on last line):");
  38.     fgets(answer, 10, stdin);
  39.     o = atoi(answer);
  40.     puts("");
  41.     for (i = 0; i < w; i++)
  42.       putchar('.');
  43.     puts("");
  44.     strcpy(t, text);
  45.     printf("%s\n", strwrap(t, w, o));
  46.     for (i = 0; i < (w-strlen(author))/2; i++)
  47.       putchar(' ');
  48.     printf("%s\n\n", author);
  49.     for (i = 0; i < (w-strlen(modified_by))/2; i++)
  50.       putchar(' ');
  51.     printf("%s\n\n", modified_by);
  52.   }
  53. }
  54.  
  55. char * strwrap(s, w, o)
  56.     char *s;
  57.     int w,o;
  58. {
  59.   char *c = s, *end;
  60.  
  61.   if (w-o < o || strlen(s) < o) return NULL;
  62.   end = s + strlen(s);
  63.   for (c += w; c < end; c += w+1) {
  64.     for (; *c != ' ' || *(c+1) == ' ' || end-c <= o; c--) if (c < s) return NULL;
  65.     *c = '\n';
  66.   }
  67.  
  68.   return s;
  69. }
  70. -- 
  71. Its most likely a     | E-MAIL: jp@michigan.com  CAT-TALK IS BACK as a FREE
  72. forgery, so save your | SYSTEM!! 313-882-2209 300-14400 V.32/V.32BIS/TurboPEP
  73. flames for someone    | Anon-UUCP: System: tygra, Login: nuucp, no pw
  74. who cares  :->        | Get file "/cat/pub/filelist" for a list of files.
  75.