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. fseek(p, 1, SEEK_CUR);
  55. }
  56. if (fclose(p))
  57. errExit(fntPath);
  58.  
  59. p = fopen(outPath, "w");
  60. if (p == NULL)
  61. errExit(outPath);
  62. for (i = 0; i < 5; i++) {
  63. for (j = 0; j < sizeof(buf); j++)
  64. buf[j] = rand() & 15;
  65. for (j = 0; j < height; i++) {
  66. for (k = 0; k < sizeof(buf); k++) {
  67. fwrite(fnt[buf[k]][j], csize, width, stdout);
  68. if (fwrite(fnt[buf[k]][j], csize, width, p) <= 0) {
  69. fclose(p);
  70. putchar('\n');
  71. errExit(outPath);
  72. }
  73. }
  74. fputc('\n', stdout);
  75. if (fputc('\n', p) < 0) {
  76. fclose(p);
  77. errExit(outPath);
  78. }
  79. }
  80. }
  81. if (fclose(p))
  82. errExit(outPath);
  83.  
  84. return 0;
  85. }
Runtime error #stdin #stdout #stderr 0s 2180KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
moji.txt: No such file or directory