A89: Re: C problem
[Prev][Next][Index][Thread]
A89: Re: C problem
Hi!
At the moment, I have no time to correct algorithm errors
(e.g. logical errors), so I will correct only syntax ones.
After this, you can compile your program (but it still does
not work, it runs somewhere in the endless loop: I will look
at this later). By the way, using push_parse_text,
NG_rationalESI etc. just for finding a fraction part is an
extremely inefficient way. It is better to do
x=fsub(x,floor(x)); // x=x-floor(x) in ANSI C
to store fraction part of x in x :-)
And, why you use floats anyway for a program which accepts
integer and produces a list of integers? Calculating with
floats is 100 times slower than with integers???
Here is a syntaxly correct program (with a list of errors):
#define RETURN_VALUE // need to be strictly at the begining
// this is not a syntax error, but
// RETURN_VALUE is used in other h files
#include <nostub.h>
#include <timath.h>
#include <estack.h>
#include <string.h>
#include <alloc.h>
#include <args.h>
int _ti89; // You forgot semicolon here
void _main(void)
{
int n,string[100],num=0,count,handle;
float b;
ti_float b_ti,a_ti=flt(1),n_ti;
char fpart_string[100];
ESI argptr=top_estack;
n=GetIntArg(argptr);
n_ti=flt(n);
while(1==1)
{
b_ti=fdiv(n_ti,a_ti);
sprintf(fpart_string, "FPart(%f)", b_ti);
push_parse_text(fpart_string);
NG_rationalESI(top_estack);
handle=display_statements(top_estack,1,1);
b_ti=atof(HeapDeref(handle));
// Use "atof" (ASCII to Float) to convert a string to float
if(0!=trunc(b_ti))
{
// b
a_ti=flt(trunc(a_ti)+1);
if(trunc(a_ti)>trunc(floor(sqrt(n_ti))))
{
push_END_TAG();
// You need not to pass "void" - it is only a convention which tells
// that the function has no parameters
for(count=num;count==1;count=count-1) // ; instead of ,
{
push_longint(string[count]);
}
push_LIST_TAG();
return;
}
// b
}
++num;
string[num]=trunc(a_ti);
if(trunc(a_ti)!=trunc(b_ti))
{
++num;
string[num]=trunc(b_ti);
}
// b
a_ti=flt(trunc(a_ti)+1);
if(trunc (a_ti)>trunc(floor(sqrt(n_ti))))
{
push_END_TAG(); // The same as above: you need not to pass "void"
for(count=num;count==1;count=count-1)
{
push_longint(string[count]);
}
push_LIST_TAG();
return;
}
}
}
Cheers,
Zeljko Juric
Follow-Ups: