I am trying to read input from a file specified on the command line and put it into a stack. This works, but it doesn't terminate the while statement when EOF is reached. Also, I am trying to read double values from a file and put them on a stack. I know how to put integers, but not doubles. Thanks Alot!
/*------------------------
----------
----------
----------
----------
----------
-
//
// Given a file of infix expressions, this program will convert the
// expression to postfix and evaluate it. Also, this program will terminate
// on bad data. Before conversion, it will check the data for extra spaces
// and uneven parentheses.
//------------------------
----------
----------
----------
----------
----------
-*/
#include <stdlib.h>
#include <stdio.h>
#include "Stack.h"
//#include "infixpost.h"
int main(int argcount , char *argvec[])
{
FILE * in;
//FILE * outfile;
//int c;
//double val;
//int iterations;
//Stack Input;
//Stack copypost;
Stack temp;
char b;
//StackEntry item;
//Stack copyinput;
//Stack Outfix;
//StackEntry a;
//iterations = 0;
if(argcount !=3)
printf("You must supply a file name to process and on to write too\n");
else
{
puts("Getting file size");
in = fopen(argvec[1],"r");
//outfile = fopen(argvec[2], "w");
if(in == NULL)
Error("Cannot open file for reading");
}
//CreateStack(&Outfix);
//CreateStack(&Input);
//CreateStack (©input);
//CreateStack (©post);
CreateStack(&temp);
do
{
while (b= (fgetc(in)!= '\n'))
{
Push(b, &temp);
}
printf("in do while loop\n");
/*while(!StackEmpty(&temp)
)
{
Pop(&item, &temp);
Push(item,&Input);
}*/
/*voidspace(&Input);
StackCopy(©input, &Input);
BracketCheck(©input, &c);
if(c == 1)
{
InfixToPostfix(&Input, &Outfix);
StackCopy(©post, &Outfix);
Value(&Outfix, &val);
print(©input, ©post, outfile);
printf("%lg", val);
iterations++;
}
else
{
printf("\n\n***Error- Unbalanced Parentheses***");
}
ClearStack(&Outfix);
ClearStack(&Input);
ClearStack(©input);
ClearStack (©post);
printf("\n%d ITERATIONS HAVE BEEN EVALUATED\n\n", iterations);
//fprintf(outfile," %d EXPRESSIONS HAVE BEEN EVALUATED\n\n", iterations);
if(b == EOF)
fclose(in);*/
}while(b !=EOF);
return;
}