home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_10_10 / 1010027a < prev    next >
Text File  |  1992-08-10  |  996b  |  52 lines

  1. #include <stdio.h>
  2.  
  3. #define MAXLINE 80
  4.        
  5. main()
  6. {
  7.     char buf[MAXLINE+1];
  8.     int nlines;
  9.            
  10.     for (nlines = 0; gets(buf) != NULL; ++nlines)
  11.     {
  12.         int temp, offset = 0;
  13.         char s[MAXLINE+1];
  14.  
  15.         printf("%d: ",nlines+1);
  16.         while (sscanf(buf+offset,"%s%n",s,&temp) == 1)
  17.         {
  18.             printf("%s ",s);
  19.             offset += temp; /* Keep track of where we are in line */
  20.         }
  21.         putchar('\n');
  22.     }
  23.     return 0;
  24. }
  25.  
  26. Executing this program with its own text as input gives this result:
  27.  
  28. 1: #include <stdio.h> 
  29. 2: 
  30. 3: #define MAXLINE 80 
  31. 4: 
  32. 5: main() 
  33. 6: { 
  34. 7: char buf[MAXLINE+1]; 
  35. 8: int nlines; 
  36. 9: 
  37. 10: for (nlines = 0; gets(buf); ++nlines) 
  38. 11: { 
  39. 12: int temp, offset = 0; 
  40. 13: char s[MAXLINE+1]; 
  41. 14: 
  42. 15: printf("%d: ",nlines+1); 
  43. 16: while (sscanf(buf+offset,"%s%n",s,&temp) == 1) 
  44. 17: { 
  45. 18: printf("%s ",s); 
  46. 19: offset += temp; /* Keep track of where we are in line */ 
  47. 20: } 
  48. 21: putchar('\n'); 
  49. 22: } 
  50. 23: return 0; 
  51. 24: } 
  52.