fork(2) 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. case EOF:
  41. fclose(p);
  42. errExit(fntPath);
  43. default:
  44. fclose(p);
  45. printf("%s: illegal character\n", fntPath);
  46. return -1;
  47. }
  48. fseek(p, 1, SEEK_CUR);
  49. }
  50. fseek(p, 1, SEEK_CUR);
  51. }
  52. if (fclose(p))
  53. errExit(fntPath);
  54.  
  55. p = fopen(outPath, "w");
  56. if (p == NULL)
  57. errExit(outPath);
  58. for (i = 0; i < 5; i++) {
  59. for (j = 0; j < sizeof(buf); j++)
  60. buf[j] = rand() & 15;
  61. for (j = 0; j < height; j++) {
  62. for (k = 0; k < sizeof(buf); k++) {
  63. fwrite(fnt[buf[k]][j], csize, width, stdout);
  64. if (fwrite(fnt[buf[k]][j], csize, width, p) <= 0) {
  65. fclose(p);
  66. putchar('\n');
  67. errExit(outPath);
  68. }
  69. }
  70. fputc('\n', stdout);
  71. if (fputc('\n', p) < 0) {
  72. fclose(p);
  73. errExit(outPath);
  74. }
  75. }
  76. }
  77. if (fclose(p))
  78. errExit(outPath);
  79.  
  80. return 0;
  81. }
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