home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / MAXLINE.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  952b  |  49 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4. ** maxline.c - returns the length of the longest line in text file
  5. **
  6. ** Released to Public Domain by Phi Nguyen
  7. **
  8. ** 03.22.96 - First release
  9. ** 03.26.96 - Chad Wallace, for use with FILECAT.C
  10. **              Uses an array of pointers to strings (ala argv)
  11. **              instead of a file.
  12. */
  13.  
  14. #include <stdio.h>
  15. #include <string.h>
  16.  
  17. unsigned int max_line(char ** str_array)
  18. {
  19.       unsigned cur_len, max = 0;
  20.  
  21.       while (*str_array != NULL)
  22.       {
  23.             cur_len = strlen(*str_array);
  24.             if (cur_len > max)
  25.                   max = cur_len;
  26.  
  27.             str_array++;
  28.       }
  29.  
  30.       return max;
  31. }
  32.  
  33. #ifdef TEST
  34.  
  35. /*
  36. ** Will return the length of the largest parameter given on the
  37. ** command line, including argv[0], the program's .EXE file.
  38. */
  39.  
  40. main(int argc, char **argv)
  41. {
  42.       printf("%i\n", max_line(argv));
  43.  
  44.       return 0;
  45. }
  46.  
  47. #endif
  48.  
  49.