This Program is supposed to get a filename, title and description of a database and then store it to and appropriate filename.

#include <fstream>
#include <iostream>
#include <cstdlib>
#include <string.h>
#include<ctime>

#define MAX_FILENAME 256
#define MAX_INIT_NAME 1024
#define MAX_DESC 1024

using namespace std;

class date { 
      public:
      int DAY; 
      int MONTH;   //Unused date class, may use it sometime soon
      int YEAR;
      };

typedef class date DATE;

class database {
      public:
      char DB_INIT_NAME[MAX_INIT_NAME];
      char DB_FILENAME[MAX_FILENAME];  //Database Class
      char DB_DESC[MAX_DESC];
      long unsigned int DB_RT_N;
      
      
      
      
      };
typedef class database DBASE ;

class recordtype {
      public:
      string RT_NAME;  
      string RT_DESC;
      long unsigned int RT_GENERIC_TYPE;
      int RT_N_R; 
      };
/*
Recordtype class, adds different record types of which properties the user could choose, for example the format i.e. employee's name etc, etc. Not used yet also.

 */
typedef class recordtype RT;

class record {
      public:
      DATE DATE_RECORDED;
      string R_S_DATA;
      DATE   R_D_DATA; //Unused record class
      long int R_I_DATA;
      
      };
typedef class record R;
DBASE CreateDataBase(); //Database base creation function
DBASE init_database(DBASE);//Array initialiser 
ofstream datafile;
string DB_INIT_SPACE, DB_DESC_SPACE, DB_FILENAME_SPACE; /* Strings that will be assigned " " 's  based on size of size of corrisponding elements. */

int DB_FILENAME_END, DB_DESC_END, DB_INIT_NAME_END,i; /* Differernt global int variables */

int main()
{   
    
    DBASE emp = CreateDataBase();
    for (i = 0;i < DB_INIT_NAME_END; i++)
    {
        DB_INIT_SPACE += " ";
    }
    
    for (i = 0; i < DB_DESC_END; i++)
    {
        DB_DESC_SPACE += " ";
    }
    
    for(i = 0; i < DB_FILENAME_END; i++)
    {
        DB_FILENAME_SPACE += " ";
    } 

    datafile.open(emp.DB_FILENAME, ios::binary | ios::trunc);  
    
    datafile << "Database Filename" << DB_FILENAME_SPACE << "Database Title" <<DB_INIT_SPACE<<"Database Descrition" << DB_DESC_SPACE<<endl ;
    datafile << emp.DB_FILENAME <<" "<<emp.DB_INIT_NAME <<" "<< emp.DB_DESC<<endl;
    
    
    
    cout <<"\n\n" << emp.DB_INIT_NAME ;
    cout <<"\n\n" << emp.DB_FILENAME <<"\n\n" ;
    cout <<"\n\n" << emp.DB_DESC << "\n\n";
    cin.get();
    cin.get();
    system("pause");
}

DBASE CreateDataBase(){
      
      DBASE newdb ;
      newdb = init_database(newdb);
      cout << "What would you like the filename of the database to be?\nFileName: " ;
      cin.getline(newdb.DB_FILENAME,MAX_FILENAME) ;
      i;
      for(i =0;i < MAX_FILENAME; i++){
                   
        if(newdb.DB_FILENAME[i] =='.' && newdb.DB_FILENAME[i+1]=='d' && newdb.DB_FILENAME[i+2]=='b')
		{break;DB_FILENAME_END = i+3;}
		
		
		else{
			if (newdb.DB_FILENAME[i] == '\0')
			{
				newdb.DB_FILENAME[i]= '.';
				newdb.DB_FILENAME[i+1]='d';
				newdb.DB_FILENAME[i+2]='b';
				DB_FILENAME_END = i+3;
				break;
            }
            else{continue;}
			}
                     
      }
      for (i=0;i < MAX_DESC;i++;)  /*  This is where the errors are being pointed to, Compiler message: 117: expected `;' before ')' token and; 125: expected primary-expression before ')' token   */ 
      {
          if (newdb.DB_DESC[i] == '\0'){
                DB_DESC_END = i+3;
                break;
          }
          else{continue;} 
      }
      for (i=0;i < MAX_DESC;i++;)  /* This has the same errors as above */
      {
          if (newdb.DB_INIT_NAME[i] == '\0'){
                DB_INIT_NAME_END = i+3;
                break;
          }
          else{continue;} 
      }
      
               
                
                
                
      cout << "\n\nWhat would you like the title of the database to be?\nTitle: ";
      cin.getline(newdb.DB_INIT_NAME,MAX_INIT_NAME)  ;
      cout << "\n\nWhat description would you attribute to " << newdb.DB_INIT_NAME << "?\nDescription: ";
      cin.getline(newdb.DB_DESC,MAX_DESC);
      return newdb;     
      
      
      
      
      }
      
DBASE init_database(DBASE db)
{
     i = 0;
     for (i=0;i<MAX_FILENAME;i++)
     {
         //cout << i <<" "<< db.DB_FILENAME << endl;
         db.DB_FILENAME[i] = '\0';
         
     }
     for (i=0;i<MAX_DESC;i++){
         
         db.DB_INIT_NAME[i]= '\0';
         db.DB_DESC[i] ='\0';
         }
         return db;
        
}

I'm not sure if this is trivial or not but I can't seem to find the pitfall,
Lines 124 and 132 contain the same two errors. I have attached the files for convenience.

Recommended Answers

All 7 Replies

I tried to compile and kept telling me that you cant have ; before )

What Compiler? and btw I'm using Dev C++, GCC .

CodeBlocks, which is a v.good compiler!

>Lines 124 and 132 contain the same two errors.
I'll answer your question with another question: How many clauses does a for loop have?

p.s. You also need to include the <string> header.

I belive three, for(Iterator = something ; while-condition; do something to limit the loop ) ?

>I belive three, for(Iterator = something ; while-condition; do something to limit the loop ) ?
That's correct. Now take a look at your code and see if it matches what you just described.

Oh I see it now, fixed and compiled without errors/warnings.

*Facepalms*
Thanks Narue :).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.