Advertisement
Guest User

Untitled

a guest
May 28th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. #include <stdio.h>;
  2.  
  3. void main(){
  4. FILE *in, *out;
  5. in = fopen("input.txt", "r");
  6. out = fopen("output.txt", "w");
  7. bool comment_ds;
  8. bool comment_sz;
  9. bool q;
  10. bool first;
  11. char b;
  12. while (!feof(in)){
  13. fscanf(in, "%c", b);
  14. if ((!comment_ds)&&(!comment_sz)){
  15. if (!q){
  16. switch (b){
  17. case '/':
  18. if (first){
  19. comment_ds = true;
  20. first = false;
  21. }
  22. else {
  23. first = true;
  24. }
  25. break;
  26. case '*':
  27. if (first){
  28. comment_sz = true;
  29. first = false;
  30. }
  31. else {
  32. fprintf(out, "*");
  33. }
  34. break;
  35. case '"':
  36. if (first){
  37. fprintf(out, "/");
  38. }
  39. q = true;
  40. fprintf(out, "%c", b);
  41. first = false;
  42. break;
  43. default:
  44. fprintf(out, "%c", b);
  45. first = false;
  46. break;
  47. }
  48. }
  49. else {
  50. switch (b){
  51. case '"':
  52. if (first){
  53. fprintf(out, "/");
  54. }
  55. q = false;
  56. fprintf(out, "%c", b);
  57. first = false;
  58. break;
  59. default:
  60. fprintf(out, "%c", b);
  61. first = false;
  62. break;
  63. }
  64. }
  65. }
  66.  
  67. if (comment_ds){
  68. fscanf(in, "%c", b);
  69. if (b == '\n'){
  70. fprintf(out, "\n");
  71. comment_ds = false;
  72. first = false;
  73. }
  74. }
  75.  
  76. if (comment_sz){
  77. fscanf(in, "%c", b);
  78. if (first){
  79. if (b == '/'){
  80. comment_sz = false;
  81. first = false;
  82. }
  83. }
  84. if (b == '*'){
  85. first = true;
  86. } else
  87. first = false;
  88. }
  89. }
  90. fclose(in);
  91. fclose(out);
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement