Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3.  
  4. int main( int argc, char** argv ) {
  5.  
  6. enum{start,test_valid,digit_test,test_digit,E__,test_digit_E,test_valid_final_E,test_valid_2,test_valid_final_final,test_valid_final} state=start;
  7. FILE *in=stdin,*out=stdout;
  8.  
  9. if(argc > 1)
  10. {
  11. in = fopen(argv[1],"r");
  12. if (in== NULL)
  13. {
  14. fprintf(stderr,"Soubor %s sa nepodarilo otvorit\n",argv[1]);
  15. }
  16. }
  17. if(argc > 2)
  18. {
  19. out = fopen(argv[2],"w");
  20. if (out == NULL)
  21. {
  22. fprintf(stderr,"Soubor %s sa nepodarilo otvorit\n",argv[2]);
  23. }
  24. }
  25.  
  26. char ch;
  27.  
  28. while((ch=fgetc(in))!=EOF)
  29. {
  30. switch (state) {
  31. case start:
  32. if(ch=='+' || ch=='-')
  33. {
  34. state=test_digit;
  35. fputc(ch,out);
  36. }
  37. else if(ch=='.')
  38. {
  39. state=test_digit;
  40. fputc(ch,out);
  41. }
  42. else if (isdigit(ch))
  43. {
  44. state=test_digit;
  45. fputc(ch,out);
  46. }
  47. break;
  48.  
  49. case test_digit:
  50. if (isdigit(ch))
  51. {
  52. state=test_digit;
  53. fputc(ch,out);
  54. }
  55. else if(ch=='.')
  56. {
  57. state=test_valid_final;
  58. fputc('.',out);
  59. }
  60. else if (ch == 'E')
  61. {
  62. fputc('E',out);
  63. state = test_digit_E;
  64. }
  65. else
  66. {
  67. state=test_valid_final_final;
  68. printf("B");
  69. }
  70. break;
  71.  
  72. /*case test_valid:
  73. if(isdigit(ch))
  74. {
  75. state=test_valid_2;
  76. fputc(ch,out);
  77. }
  78. break;*/
  79. case test_digit_E:
  80. if (isdigit(ch))
  81. {
  82. state=test_digit_E;
  83. fputc(ch,out);
  84. }
  85. else if(ch=='.')
  86. {
  87. state=test_valid_final_E;
  88. fputc('.',out);
  89. }
  90. else
  91. {
  92. state=test_valid_final_final;
  93. }
  94. break;
  95.  
  96. case E__:
  97. break;
  98.  
  99. case test_valid_final_E:
  100. state=start;
  101. fputc(ch,out);
  102. printf(" - nevalidni\n");
  103. break;
  104.  
  105. case test_valid_final:
  106. fputc(ch,out);
  107. state = test_digit;
  108. break;
  109.  
  110. case test_valid_final_final:
  111. printf("BEPIS");
  112. printf(" - validni\n");
  113. state = start;
  114. break;
  115.  
  116. default:
  117. break;
  118. }
  119. }
  120. fclose(in);
  121. fclose(out);
  122.  
  123. return 0;
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement