touint8array.c 784 B

123456789101112131415161718192021222324252627282930
  1. /*
  2. ** 2023-08-29
  3. **
  4. ** The author disclaims copyright to this source code. In place of
  5. ** a legal notice, here is a blessing:
  6. **
  7. ** May you do good and not evil.
  8. ** May you find forgiveness for yourself and forgive others.
  9. ** May you share freely, never taking more than you give.
  10. **
  11. *************************************************************************
  12. ** This file contains a tool for writing out the contents of stdin as
  13. ** a comma-separated list of numbers, one per byte.
  14. */
  15. #include <stdio.h>
  16. int main(int argc, char const **argv){
  17. int i;
  18. int rc = 0, colWidth = 30;
  19. int ch;
  20. printf("[");
  21. for( i=0; EOF!=(ch = fgetc(stdin)); ++i ){
  22. if( 0!=i ) printf(",");
  23. if( i && 0==(i%colWidth) ) puts("");
  24. printf("%d",ch);
  25. }
  26. printf("]");
  27. return rc;
  28. }