fork(1) download
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. FILE* fp;
  6. char buf[640];
  7. errno_t err;
  8. int x_size, y_size;
  9. int max_gray;
  10. int ix, iy;
  11.  
  12. err = fopen_s(&fp, "std0.pgm", "rb");
  13. if (err) {
  14. fprintf(stderr, "fopen_s\n");
  15. return 1;
  16. }
  17.  
  18. // P5
  19. fgets(buf, sizeof buf, fp);
  20. if (buf[0] != 'P' || buf[1] != '5') {
  21. fprintf(stderr, "not P5\n");
  22. return 1;
  23. }
  24.  
  25. // x y
  26. x_size = y_size = 0;
  27. while (x_size == 0) {
  28. fgets(buf, sizeof buf, fp);
  29. if (buf[0] == '#') continue;
  30. sscanf_s(buf, "%d%d", &x_size, &y_size);
  31. }
  32.  
  33. // max
  34. max_gray = 0;
  35. while (max_gray == 0) {
  36. fgets(buf, sizeof buf, fp);
  37. if (buf[0] == '#') continue;
  38. sscanf_s(buf, "%d", &max_gray);
  39. }
  40.  
  41. printf("%d %d\n", x_size, y_size);
  42. printf("%d\n", max_gray);
  43.  
  44. for (ix = 0; ix < x_size; ix++) {
  45. for (iy = 0; iy < y_size; iy++) {
  46. printf("%02x", fgetc(fp));
  47. }
  48. printf("\n");
  49. }
  50.  
  51. fclose(fp);
  52. return 0;
  53. }
  54.  
  55. /*
  56. 32 32
  57. 255
  58. fffffffffffffffffffffffbaf7f7f7f7f7f7f7faffbffffffffffffffffffff
  59. fffffffffffffffffffff4e0651717171717130556dff4ffffffffffffffffff
  60. ffffffffffffffffffffb2528bafafafafaf8e261d4db2ffffffffffffffffff
  61. ffffffffffffffffedc2864dbaffffffffffdc6f474786c2edffffffffffffff
  62. ffffffffffffffffc74273e0f3fffffffffff9e6dfdf7342c7ffffffffffffff
  63. fffffffffffff7b065156fffffffffffffffffffffff6f1565b0f7ffffffffff
  64. ffffffffffffef57030d78ffffffffffffffffffffff780d0357efffffffffff
  65. ffffffffffffef57298dcdffffffffffffffffffffffcd8d2957efffffffffff
  66. ffffffffffe1b3413fd7ffffffffffffffffffffffffffd73f41b3e1ffffffff
  67. ffffffffff9a250d3fd7ffffffffffffffffffffffffffd73f0d259affffffff
  68. ffffffffff8700003fd7ffffffffffffffffffffffffffd73f000087ffffffff
  69. ffffffffff8700003fd7ffffffffffffffffffffffffffd73f000087ffffffff
  70. ffffffffff8700003fd7ffffffffffffffffffffffffffd73f000087ffffffff
  71. ffffffffff8700003fd7ffffffffffffffffffffffffffd73f000087ffffffff
  72. ffffffffff8700003fd7ffffffffffffffffffffffffffd73f000087ffffffff
  73. ffffffffff8700003fd7ffffffffffffffffffffffffffd73f000087ffffffff
  74. ffffffffff8700003fd7ffffffffffffffffffffffffffd73f000087ffffffff
  75. ffffffffff8700003fd7ffffffffffffffffffffffffffd73f000087ffffffff
  76. ffffffffff8700003fd7ffffffffffffffffffffffffffd73f000087ffffffff
  77. ffffffffff8700003fd7ffffffffffffffffffffffffffd73f000087ffffffff
  78. ffffffffff8700003fd7ffffffffffffffffffffffffffd73f000087ffffffff
  79. ffffffffff8700003fd7ffffffffffffffffffffffffffd73f000087ffffffff
  80. ffffffffff8700003fd7ffffffffffffffffffffffffffd73f000087ffffffff
  81. ffffffffff9a250d3fd7ffffffffffffffffffffffffffd73f0d259affffffff
  82. ffffffffffe1b3413fd7ffffffffffffffffffffffffffd73f41b3e1ffffffff
  83. ffffffffffffef57298dcdffffffffffffffffffffffcd8d2957efffffffffff
  84. ffffffffffffef57030d78ffffffffffffffffffffff780d0357efffffffffff
  85. fffffffffffff7b065156fffffffffffffffffffffff6f1565b0f7ffffffffff
  86. ffffffffffffffffc74273dfdfe6f9fffffffffff3e07342c7ffffffffffffff
  87. ffffffffffffffffedc28647476fdcffffffffffba4d86c2edffffffffffffff
  88. ffffffffffffffffffffb24d1d268eafafafafaf8b52b2ffffffffffffffffff
  89. fffffffffffffffffffff4df560513171717171765e0f4ffffffffffffffffff
  90. */
  91.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty