Ok,here´s what i have done so far:
Code:
int main(int argc,char *argv[])
{
FILE *fp;
char comando[20];
char argumento[20];
int arg_numerico;
fp=fopen(argv[1],"r");
if(fp==NULL)
{
printf("Impossivel abrir o ficheiro %s\n", argv[1]);
}
else
{
while((fscanf(fp,"%s %s",comando,argumento))!=EOF)
{
if(analisa(argumento))
{
if(comando=="POP")
pop(&l,argumento);
else push(&l,valor_da_var(&v, argumento));
}
else
{
arg_numerico=atoi(argumento);
executa_comando(comando,arg_numerico);
}
}
}
return 0;
}
So,the function analisa tells me if its a number of not,and does the atoi thing.The function executa comando calls all the other functions,push,pop,mul and so on.The problem is when i have a line like this:
PUSH 34
It gets 2 arguments,comando and argument.
But if i have
MUL
ADD
it also gets 2 arguments,and it should only catch mul,whihc is the command(in this case,it would consider add as an argument for mul)The problem is that i´m "fetching" 2 strings,but sometimes,when the commands dont have any arguments,i want to catch only one.Can someone help me with this?