About Store Forum Documentation Contact
Donations:
140$/mo



Post Reply 
C++ question. File I/O & Dynamic Memory Array
Author Message
kaito Offline
Member

Post: #1
C++ question. File I/O & Dynamic Memory Array
I use extern to declare the array that is created inside the function which is responsible for uploading the data, but not good, because it produces error C2109: subscript requires array or pointer type, in line D.text (0,0.9-0.5*(i+j),cadena[i][j]); in function Draw.

Code:
New Code in next post

EDIT: About extern, I searched more information, and this sentence no is for this. It's used in header files.
03-19-2009 08:22 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
Re: C++ question. File I/O & Dynamic Memory Array
Hi

for the string please use 'Str' class.

and for text files 'FileText' class, there is a tutorial on writing such files.
03-20-2009 08:34 PM
Find all posts by this user Quote this message in a reply
kaito Offline
Member

Post: #3
Re: C++ question. File I/O & Dynamic Memory Array
Text File.

Code:
4
#="Linea0"
#="Linea1"
#="Linea2"
#="Linea3"



New code.

Code:
/******************************************************************************/
#include "stdafx.h"
/******************************************************************************/

// Global Variable and functions

I16 NEvent; // Save Event Number
char (*cadena)[50]=new char [1][50];  // string variable


// Load File Function

Bool LoadDatas () {    
    FileText archive;
    if (archive.read("Data/datos.txt")) {
        int iCounter=0;
        NEvent=archive.getInt();
        delete [] cadena;       // Delete global variable
        char (*cadena)[50]=new char [NEvent][50];   // Resize global variable
        for (;archive.level();) {
            if (archive.cur("#")) {archive.getName(cadena[iCounter]);}
            ++iCounter;
        }
        return true;
    }
    return false;
}


/******************************************************************************/
void InitPre()
{
   App.name="Start";
   App.flag=APP_NO_FX;          
   PakAdd("../data/engine.pak");
}
/******************************************************************************/
Bool Init()
{
   LoadDatas();
   return true;
}
/******************************************************************************/
void Shut()
{

}
/******************************************************************************/
Bool Main()
{
    if(Kb.bp(KB_ESC))return false;
    return true;
}
/******************************************************************************/
void Draw()
{
    for (int i=0; i<NEvent; i++) {
            D.text (0,0.9-0.5*(i),cadena[i]);
    }
}
/******************************************************************************/


The code produces the following result

[Image: capturan.png]



The code shows signs displayed, but no words.

Thanks.
03-22-2009 02:13 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
Re: C++ question. File I/O & Dynamic Memory Array
1. Please download the latest engine version
2. Please use 'Str' class for strings
3. You can use this code (I've tested it, and it workd fine)

Code:
/******************************************************************************/
#include "stdafx.h"
#include "../resource.h"
/******************************************************************************/
Int       num;
Memb<Str> names;
/******************************************************************************/
void InitPre()
{
   App.name("Project");
   App.icon=(Char*)IDI_ICON1;
   App.flag=APP_FULL_TOGGLE|APP_KB_EXCLUSIVE|APP_MINIMIZABLE|APP_MAXIMIZABLE;
}
Bool Init()
{
   Text_ds.color=BLACK;
   Text_ds.shadow=0;

   FileText f;
   if(f.read("test.txt"))
   {
      num=f.getInt();
      for(;f.level();)
      {
         if(f.cur("#"))names.New()=f.getName();
      }
   }

   return true;
}
void Shut()
{
}
/******************************************************************************/
Bool Main()
{
   if(Kb.bp(KB_ESC))return false;
   return true;
}
/******************************************************************************/
void Draw()
{
   D.clear(WHITE);
   D.text(0,0.9,S+Tm.fps());
   D.text(0,0.8,S+num);
   REPA(names)D.text(0,0.7-i*0.1,names[i]);
}
/******************************************************************************/
03-22-2009 02:25 PM
Find all posts by this user Quote this message in a reply
kaito Offline
Member

Post: #5
Re: C++ question. File I/O & Dynamic Memory Array
Thanks again.
03-22-2009 02:37 PM
Find all posts by this user Quote this message in a reply
Post Reply