fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. static void errExit(const char *s)
  5. {
  6. perror(s);
  7. exit(-1);
  8. }
  9.  
  10. int main()
  11. {
  12. const int base = 16;
  13. const int height = 5;
  14. const int width = 3;
  15. const int csize = 3;
  16. const char *fntPath = "moji.txt";
  17. const char *outPath = "date.txt";
  18. char fnt[base][height][width][csize];
  19. char buf[8];
  20. int c, i, j, k;
  21. FILE *p;
  22.  
  23. p = fopen(fntPath, "r");
  24. if (p == NULL)
  25. errExit(fntPath);
  26. for (i = 0; i < base; i++)
  27. for (j = 0; j < height; j++)
  28. for (k = 0; k < width; k++) {
  29. fnt[i][j][k][0] = 0xE2;
  30. c = fgetc(p);
  31. switch(c) {
  32. case '0':
  33. fnt[i][j][k][1] = 0x80;
  34. fnt[i][j][k][2] = 0x95;
  35. break;
  36. case '1':
  37. fnt[i][j][k][1] = 0x97;
  38. fnt[i][j][k][2] = 0x8F;
  39. break;
  40. default:
  41. fclose(p);
  42. if (c < 0)
  43. errExit(fntPath);
  44. else {
  45. printf("%s: illegal character\n", fntPath);
  46. return -1;
  47. }
  48. }
  49. if (fseek(p, 1, SEEK_CUR) == EOF) {
  50. fclose(p);
  51. errExit(fntPath);
  52. }
  53. }
  54. if (fclose(p))
  55. errExit(fntPath);
  56.  
  57. p = fopen(outPath, "w");
  58. if (p == NULL)
  59. errExit(outPath);
  60. for (i = 0; i < 5; i++) {
  61. for (j = 0; j < sizeof(buf); j++)
  62. buf[j] = rand() & 15;
  63. for (j = 0; j < height; i++) {
  64. for (k = 0; k < sizeof(buf); k++) {
  65. fwrite(fnt[buf[k]][j], csize, width, stdout);
  66. if (fwrite(fnt[buf[k]][j], csize, width, p) <= 0) {
  67. fclose(p);
  68. putchar('\n');
  69. errExit(outPath);
  70. }
  71. }
  72. fputc('\n', stdout);
  73. if (fputc('\n', p) < 0) {
  74. fclose(p);
  75. errExit(outPath);
  76. }
  77. }
  78. }
  79. if (fclose(p))
  80. errExit(outPath);
  81.  
  82. return 0;
  83. }
Runtime error #stdin #stdout #stderr 0s 2136KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
moji.txt: No such file or directory