Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.45 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main ()
  5. {
  6. //used to access two files
  7. FILE *input_file,*output_file;
  8. char c,e;
  9. int invalid=0;
  10. float xcord=0,ycord=0;
  11. float num=0; // whether we omit a digit
  12. float d=0.1;
  13. input_file = fopen("in1.txt","r");
  14. if (input_file == NULL)
  15. {
  16. printf ("File in1.txt cannot be opened \n");
  17. exit(1); // return 0
  18. }
  19. output_file = fopen ("out1.txt","w");
  20. if (output_file == NULL)
  21. {
  22. printf ("File out1.txt cannot be opened \n");
  23. exit(1);
  24. }
  25.  
  26. c = fgetc(input_file);
  27. while (c != EOF) // EOF----> end of file
  28. {
  29. num=0;
  30. d=0.1;
  31.  
  32. if(c == 'I'){
  33. c = fgetc(input_file);
  34. if (c == 'N'){
  35. c = fgetc(input_file);
  36. if (c == 'I'){
  37. c = fgetc(input_file);
  38. if (c == 'T'){
  39. c = fgetc(input_file);
  40. if (c == 'I'){
  41. c = fgetc(input_file);
  42. if (c == 'A'){
  43. c = fgetc(input_file);
  44. if (c == 'L'){
  45. c = fgetc(input_file);
  46. c = fgetc(input_file);
  47. if (c == '('){
  48. c = fgetc(input_file);
  49. while (c>='0'&&c<='9'){
  50. num=num*10+c-'0';
  51. c=fgetc(input_file);
  52. }
  53. if (c=='.'){
  54. c=fgetc(input_file);
  55. while (c>='0'&&c<='9'){
  56. num=num+d*(c-'0');
  57. d=d*0.1;
  58. c=fgetc(input_file);
  59. }
  60. }
  61. xcord=num;
  62. num=0;
  63. d=0.1;
  64. if (c == ','){
  65. c = fgetc(input_file);
  66. while (c>='0'&&c<='9'){
  67. num=num*10+c-'0';
  68. c=fgetc(input_file);
  69. }
  70. if (c=='.'){
  71. c=fgetc(input_file);
  72. while (c>='0'&&c<='9'){
  73. num=num+d*(c-'0');
  74. d=d*0.1;
  75. c=fgetc(input_file);
  76. }
  77. }
  78. ycord=num;
  79. num=0;
  80. if (c == ')'){
  81. c=fgetc(input_file);
  82. if(c != 'L'||(c != 'R')||(c != 'U')||(c != 'D')||(c != 'I')){
  83. c=fgetc(input_file);
  84. }
  85. }
  86. }
  87. }
  88. }
  89. }
  90. }
  91. }}}}
  92.  
  93. if(c == 'L'){
  94. c = fgetc(input_file);
  95. if (c == 'E'){
  96. c = fgetc(input_file);
  97. if (c == 'F'){
  98. c = fgetc(input_file);
  99. if (c == 'T'){
  100. c = fgetc(input_file);
  101. c = fgetc(input_file);
  102. while (c>='0'&&c<='9'){
  103. num=num*10+c-'0';
  104. c=fgetc(input_file);
  105. }
  106. if (c=='.'){
  107. c=fgetc(input_file);
  108. if(c>='0'&&c<='9'){
  109. while (c>='0'&&c<='9'){
  110. num=num+d*(c-'0');
  111. d=d*0.1;;
  112. c=fgetc(input_file);
  113. }
  114. }
  115. }
  116. xcord=xcord-num;
  117. num=0;
  118. c = fgetc(input_file);
  119. }
  120. }
  121. }
  122. }
  123. if (c == 'R'){
  124. c = fgetc(input_file);
  125. if (c == 'I'){
  126. c = fgetc(input_file);
  127. if (c == 'G'){
  128. c = fgetc(input_file);
  129. if (c == 'H'){
  130. c = fgetc(input_file);
  131. if (c == 'T'){
  132. c = fgetc(input_file);
  133. c = fgetc(input_file);
  134. while (c>='0'&&c<='9'){
  135. num=num*10+c-'0';
  136. c=fgetc(input_file);
  137. }
  138. if (c=='.'){
  139. c=fgetc(input_file);
  140. if(c>='0'&&c<='9'){
  141. while (c>='0'&&c<='9'){
  142. num=num+d*(c-'0');
  143. d=d*0.1;;
  144. c=fgetc(input_file);
  145. }
  146. }
  147. }
  148. xcord=xcord+num;
  149. num=0;
  150. c = fgetc(input_file);
  151. }
  152. }
  153. }
  154. }
  155. }
  156. if (c == 'U'){
  157. c = fgetc(input_file);
  158. if (c == 'P'){
  159. c = fgetc(input_file);
  160. c = fgetc(input_file);
  161. while (c>='0'&&c<='9'){
  162. num=num*10+c-'0';
  163. c=fgetc(input_file);
  164. }
  165. if (c=='.'){
  166. c=fgetc(input_file);
  167. if(c>='0'&&c<='9'){
  168. while (c>='0'&&c<='9'){
  169. num=num+d*(c-'0');
  170. d=d*0.1;;
  171. c=fgetc(input_file);
  172. }
  173. }
  174. }
  175. ycord=ycord+num;
  176. num=0;
  177. c = fgetc(input_file);
  178. }
  179. }
  180. if (c == 'D'){
  181. c = fgetc(input_file);
  182. if (c == 'O'){
  183. c = fgetc(input_file);
  184. if (c == 'W'){
  185. c = fgetc(input_file);
  186. if (c == 'N'){
  187. c = fgetc(input_file);
  188. c = fgetc(input_file);
  189. while (c>='0'&&c<='9'){
  190. num=num*10+c-'0';
  191. c=fgetc(input_file);
  192. }
  193. if (c=='.'){
  194. c=fgetc(input_file);
  195. if(c>='0'&&c<='9'){
  196. while (c>='0'&&c<='9'){
  197. num=num+d*(c-'0');
  198. d=d*0.1;;
  199. c=fgetc(input_file);
  200. }
  201. }
  202. }
  203. ycord=ycord-num;
  204. num=0;
  205. c = fgetc(input_file);
  206. }
  207. }
  208. }
  209. }
  210. c=fgetc(input_file);
  211. }
  212. fprintf (output_file, "Final Position: (%g,%g)", xcord,ycord);
  213. fclose (input_file);
  214. fclose (output_file);
  215. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement