How to get whole string using gfxdrawtext

I have a file ;

Bitcoin is the first successful internet money based on peer-to-peer technology; whereby no central bank or authority is involved in the transaction and production of the Bitcoin currency. It was created by an anonymous individual/group under the name, Satoshi Nakamoto. The source code is available publicly as an open source project, anybody can look at it and be part of the developmental process.
Bitcoin is changing the way we see money as we speak. The idea was to produce a means of exchange, independent of any central authority, that could be transferred electronically in a secure, verifiable and immutable way. It is a decentralized peer-to-peer internet currency making mobile payment easy, very low transaction fees, protects your identity, and it works anywhere all the time with no central authority and banks.
Bitcoin is designed to have only 21 million BTC ever created, thus making it a deflationary currency. Bitcoin uses the <a href="https://www.coingecko.com/en?hashing_algorithm=SHA-256">SHA-256</a> hashing algorithm with an average transaction confirmation time of 10 minutes. Miners today are mining Bitcoin using ASIC chip dedicated to only mining Bitcoin, and the hash rate has shot up to peta hashes.
Being the first successful online cryptography currency, Bitcoin has inspired other alternative currencies such as <a href="https://www.coingecko.com/en/coins/litecoin">Litecoin</a>, <a href="https://www.coingecko.com/en/coins/peercoin">Peercoin</a>, <a href="https://www.coingecko.com/en/coins/primecoin">Primecoin</a>, and so on.
The cryptocurrency then took off with the innovation of the turing-complete smart contract by <a href="https://www.coingecko.com/en/coins/ethereum">Ethereum</a> which led to the development of other amazing projects such as <a href="https://www.coingecko.com/en/coins/eos">EOS</a>, <a href="https://www.coingecko.com/en/coins/tron">Tron</a>, and even crypto-collectibles such as <a href="https://www.coingecko.com/buzz/ethereum-still-king-dapps-cryptokitties-need-1-billion-on-eos">CryptoKitties</a>.

which was created formatting some json strings the coinGecko API
I want to be able to display it in this box....

As you can see, only the last line is printed when I use;

_SECTION_BEGIN("Get File Info");
fh=fopen("C:\\Program Files\\AmiBroker\\...\\...\\BTC.txt","r",True);
if(fh);
{
	while(! feof(fh))
	{
		fileData = (fgets(fh));
	}
fclose(fh);
}
GfxDrawText(fileData,const1+20,const2+90,const3-200,const4-100,16);

and only the first line is printed when I instead use

const1=50;
const2=50;
const3=1400;
const4=800;

_SECTION_BEGIN("Get File Info");
fh=fopen("C:\\Program Files\\AmiBroker\\...\\...\\BTC.txt","r",True);
if(fh);
{
		fileData = (fgets(fh));
fclose(fh);
}
GfxDrawText(fileData,const1+20,const2+90,const3-200,const4-100,16);

My understanding with the first example above is that I am testing for the end of the file but I am only reading the last line. How can I get the whole file contents?

@SpandexMan, try something like this example (reading all the file lines and concatenate them in a new variable):

lines = "";
filename = "C:\\tmp\\BTC.txt";
fh =  fopen( filename, "r", True );
// adapted from Amibroker snippet
if( fh )
{
    while( ! feof( fh ) )
    {
        line = fgets( fh ); // read a line of text
        _TRACE( line );

        if( line != "" )
            lines += line;
    }
    fclose( fh );
}
else
{
    Error( StrFormat("ERROR: file %s can not be open", filename));
}

// Draw it
const1 = 50;
const2 = 50;
const3 = 1400;
const4 = 800;
GfxDrawText( lines, const1 + 20, const2 + 90, const3 - 200, const4 - 100, 16 );
2 Likes

Perfect. Thanks @beppe that is absolutely fantastic!

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.