Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main ()
- {
- //used to access two files
- FILE *input_file,*output_file;
- char c,e;
- int invalid=0;
- float xcord=0,ycord=0;
- float num=0; // whether we omit a digit
- float d=0.1;
- input_file = fopen("in1.txt","r");
- if (input_file == NULL)
- {
- printf ("File in1.txt cannot be opened \n");
- exit(1); // return 0
- }
- output_file = fopen ("out1.txt","w");
- if (output_file == NULL)
- {
- printf ("File out1.txt cannot be opened \n");
- exit(1);
- }
- c = fgetc(input_file);
- while (c != EOF) // EOF----> end of file
- {
- num=0;
- d=0.1;
- if(c == 'I'){
- c = fgetc(input_file);
- if (c == 'N'){
- c = fgetc(input_file);
- if (c == 'I'){
- c = fgetc(input_file);
- if (c == 'T'){
- c = fgetc(input_file);
- if (c == 'I'){
- c = fgetc(input_file);
- if (c == 'A'){
- c = fgetc(input_file);
- if (c == 'L'){
- c = fgetc(input_file);
- c = fgetc(input_file);
- if (c == '('){
- c = fgetc(input_file);
- while (c>='0'&&c<='9'){
- num=num*10+c-'0';
- c=fgetc(input_file);
- }
- if (c=='.'){
- c=fgetc(input_file);
- while (c>='0'&&c<='9'){
- num=num+d*(c-'0');
- d=d*0.1;
- c=fgetc(input_file);
- }
- }
- xcord=num;
- num=0;
- d=0.1;
- if (c == ','){
- c = fgetc(input_file);
- while (c>='0'&&c<='9'){
- num=num*10+c-'0';
- c=fgetc(input_file);
- }
- if (c=='.'){
- c=fgetc(input_file);
- while (c>='0'&&c<='9'){
- num=num+d*(c-'0');
- d=d*0.1;
- c=fgetc(input_file);
- }
- }
- ycord=num;
- num=0;
- if (c == ')'){
- c=fgetc(input_file);
- if(c != 'L'||(c != 'R')||(c != 'U')||(c != 'D')||(c != 'I')){
- c=fgetc(input_file);
- }
- }
- }
- }
- }
- }
- }
- }}}}
- if(c == 'L'){
- c = fgetc(input_file);
- if (c == 'E'){
- c = fgetc(input_file);
- if (c == 'F'){
- c = fgetc(input_file);
- if (c == 'T'){
- c = fgetc(input_file);
- c = fgetc(input_file);
- while (c>='0'&&c<='9'){
- num=num*10+c-'0';
- c=fgetc(input_file);
- }
- if (c=='.'){
- c=fgetc(input_file);
- if(c>='0'&&c<='9'){
- while (c>='0'&&c<='9'){
- num=num+d*(c-'0');
- d=d*0.1;;
- c=fgetc(input_file);
- }
- }
- }
- xcord=xcord-num;
- num=0;
- c = fgetc(input_file);
- }
- }
- }
- }
- if (c == 'R'){
- c = fgetc(input_file);
- if (c == 'I'){
- c = fgetc(input_file);
- if (c == 'G'){
- c = fgetc(input_file);
- if (c == 'H'){
- c = fgetc(input_file);
- if (c == 'T'){
- c = fgetc(input_file);
- c = fgetc(input_file);
- while (c>='0'&&c<='9'){
- num=num*10+c-'0';
- c=fgetc(input_file);
- }
- if (c=='.'){
- c=fgetc(input_file);
- if(c>='0'&&c<='9'){
- while (c>='0'&&c<='9'){
- num=num+d*(c-'0');
- d=d*0.1;;
- c=fgetc(input_file);
- }
- }
- }
- xcord=xcord+num;
- num=0;
- c = fgetc(input_file);
- }
- }
- }
- }
- }
- if (c == 'U'){
- c = fgetc(input_file);
- if (c == 'P'){
- c = fgetc(input_file);
- c = fgetc(input_file);
- while (c>='0'&&c<='9'){
- num=num*10+c-'0';
- c=fgetc(input_file);
- }
- if (c=='.'){
- c=fgetc(input_file);
- if(c>='0'&&c<='9'){
- while (c>='0'&&c<='9'){
- num=num+d*(c-'0');
- d=d*0.1;;
- c=fgetc(input_file);
- }
- }
- }
- ycord=ycord+num;
- num=0;
- c = fgetc(input_file);
- }
- }
- if (c == 'D'){
- c = fgetc(input_file);
- if (c == 'O'){
- c = fgetc(input_file);
- if (c == 'W'){
- c = fgetc(input_file);
- if (c == 'N'){
- c = fgetc(input_file);
- c = fgetc(input_file);
- while (c>='0'&&c<='9'){
- num=num*10+c-'0';
- c=fgetc(input_file);
- }
- if (c=='.'){
- c=fgetc(input_file);
- if(c>='0'&&c<='9'){
- while (c>='0'&&c<='9'){
- num=num+d*(c-'0');
- d=d*0.1;;
- c=fgetc(input_file);
- }
- }
- }
- ycord=ycord-num;
- num=0;
- c = fgetc(input_file);
- }
- }
- }
- }
- c=fgetc(input_file);
- }
- fprintf (output_file, "Final Position: (%g,%g)", xcord,ycord);
- fclose (input_file);
- fclose (output_file);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement