LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-15-2004, 06:30 PM   #1
bru
Member
 
Registered: Sep 2003
Location: South Carolina
Distribution: Ubuntu, CentOS, BT4, Debian
Posts: 132

Rep: Reputation: 15
couple C++ syntax errors


I'm trying to creat a program in C++ the creats a database for videos!
Using GCC-3.3.1, command = g++ file.cpp -g


Problem #1= syntax error before `void'
Problem #2 = syntax error before `[' token
problems are annotated with 'RED' coments
Code:
#include <iostream>

#include <cstring>

#include <fstream>

#include <string>            

#include <stdio.h>

#include <iomanip>



using namespace std;



struct Videos

{                   // making record fields

   char title[80];

   char director[20];

   char stars[80] ;

   int length_of_movie ;

   int how_many;

};



//functions

void add_Video(int&, Videos []);     //Prototypes - note the second argument is of the struct Video

void list_Videos(int, Videos []); 

void search_list(int,Videos []);

void showmenu(int) ;

void Read_Data_File(int&, Videos []) ;

void Save_to_File(int, Videos []) ;

void usr_Choice(char& choice) ;

void Delete_Video(int&, Videos []) ;

void Quit_msg();



int main()

{


//the Decleration of things

    int num_videos;
    char choice; 

    fstream videosdb; // data file

    Videos The_Videos [50]; //The array

	// calls function to read data file 

	void Read_Data_File(int&, Videos []) ;



	// do-while loop for repetitive requests or operations. 

   do

   {

      // calls function to display menu choices.

	  showmenu(num_videos); 

     

	  // calls function which allows choice of menu options

	  usr_Choice(choice) ;

  



    do

    {

	cout << "What is your choice?" << endl;

	cin >> choice;

	choice = toupper(choice);





	switch (choice) 				      	

	  {                                                       

/*add*/		case 'A':  add_Video(num_videos, The_Videos);

			   Save_to_File(num_videos, The_Videos);

			cout << "\n number of videos in main after Add: "; 

			cout << num_videos << endl;                 

			break;



/*list*/	case 'L':  list_Videos(num_videos, The_Videos);

			break;



/*delete*/	case 'D': Delete_Video(num_videos, The_Videos);

			  Save_to_File(num_videos, The_Videos);

			break;



// /*search*/	case 'S': search_list(num_videos, The_Videos);

			break;



/*Quit*/	case 'Q':  break;

	        default:   cout << "Error in choice.  Please try again."  << endl;

      }

   }while (choice != 'Q');





   videosdb.close();



   Quit_msg();

   return 0;



} // end of main function



/**************************************************************************************************************/

/* Readng the Data file */

void Read_Data_File(int&, Video[]) //Problem #1 



{

    int length_of_movie;
    int how_many;


/*  ofstream videosdb; */

    videosdb.open("videosdb.dat");

    Video The_Videos [50]; //Problem #2
Thanks in advance for the help!!!
 
Old 05-15-2004, 07:52 PM   #2
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
Why the extra function declaration towards the beginning of main()?

Code:
void Read_Data_File(int&, Videos []) ;
Not sure whether that is causing the first error, but it certainly isn't correct. As for the second error, where is the data type "Video" defined?
 
Old 05-15-2004, 08:07 PM   #3
bru
Member
 
Registered: Sep 2003
Location: South Carolina
Distribution: Ubuntu, CentOS, BT4, Debian
Posts: 132

Original Poster
Rep: Reputation: 15
????? ?????
What?????
are you stating that in the begining of main I should just
Code:
 void Read_Data_File () ;
Instead of
Code:
 void Read_Data_File (int&, Video[]) ;


"Video" is another one of my great fat fingering tricks where I forget witch thing I called what.

Last edited by bru; 05-15-2004 at 08:09 PM.
 
Old 05-15-2004, 09:08 PM   #4
lramos85
Member
 
Registered: Sep 2003
Location: Riverside, Ca
Distribution: Gentoo, FC3
Posts: 125

Rep: Reputation: 15
/* Readng the Data file */

void Read_Data_File(int&, Video[]) //Problem #1
{
...
}

In that fuction I think you need something like:

void Read_Data_File(int variable, Videos array_Video[]) //Problem #1

and you also need to send the variables when you call the function I don't see you do that:

// calls function to read data file

void Read_Data_File(num_video, The_Videos) ;

hope this is it
 
Old 05-15-2004, 10:44 PM   #5
bru
Member
 
Registered: Sep 2003
Location: South Carolina
Distribution: Ubuntu, CentOS, BT4, Debian
Posts: 132

Original Poster
Rep: Reputation: 15
OOOOOOOOOOHHHHHHHHHH

I see thank you very much!!!
[edit]
have any idea what this mean??? Having trouble finding an answer on google.com
error: type specifier omitted for parameter `The_Videos[]'

Code:
.
.
.
} //end of previous function




/**************************************************************************************************************/

//Saving the Data file

void Save_to_File(int num_videos, int how_many, The_Videos[])//error is here 


{ //begining of new function
[/edit]

Last edited by bru; 05-15-2004 at 11:33 PM.
 
Old 05-16-2004, 12:04 AM   #6
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
For that first declaration I mentioned (inside of main), if you are trying to call the function at that point, it should look something like:

Code:
Read_Data_File(num_videos, The_Videos);
The 'void' should precede it only when you are declaring or defining the function, not when you call (execute) the function. Also, in the definition of that function (at the bottom of your first post), you should be giving some variable names to the arguments, like this:

Code:
void Read_Data_File( int & numberOfVideos, Videos[] The_Videos)
or whatever those arguments are supposed to represent.

In your last question about 'type specifier omitted', you did not declare what data type The_Videos[] is in the argument list. Should be 'Videos The_Videos[]' or some such.
 
Old 05-16-2004, 12:20 AM   #7
bru
Member
 
Registered: Sep 2003
Location: South Carolina
Distribution: Ubuntu, CentOS, BT4, Debian
Posts: 132

Original Poster
Rep: Reputation: 15
Ok I guess I don't see like I thought I did!

i'm giving up for tonight
+ = brain

Thanks for trying to help though!
 
Old 05-16-2004, 01:02 PM   #8
eric.r.turner
Member
 
Registered: Aug 2003
Location: Planet Earth
Distribution: Linux Mint
Posts: 216

Rep: Reputation: 31
Problem #1: The structure type is Videos not Video. Also, you need to give names to your arguments.

Problem #2: The structure type is Videos not Video.

Problem #3: You have an extra "do {" without a closing "} while()".

I recommend that you work on improving your coding style:
  • Use consistent indenting (spaces, not tabs).
  • Use consistent function and variable naming conventions; the most common thing you'll see is to start functions and variables with a lowercase letter, then uppercase the first letter of each word in the function or variable name: readDataFile instead of Read_Data_File. Classes and structures usually start with upper case: Video, Menu, Person, etc. Constants are usually uppercase separated by underscores (_): PI, MAX_LENGTH, etc.
  • Comments should add something that is not obvious from the code. Things like:
    Code:
    /* Reading the data file. */
    void readDataFile( int& index, Videos videos[] ) {...}
    don't really add anything worthwhile. Try to make the code as self-documenting as possible, and save your comments for the non-obvious things.
  • Be careful of how you name things. Calling a structure Videos when it really represents just one video rather than multiple videos is probably not a great way to go. Instead, call it Video.
  • Always give names to your function arguments, even in the function declarations. That goes a long way toward writing self-documenting code. For example:
    Code:
    int m(int,int);
    is not as descriptive as
    Code:
    int multiply(int operand1, int operand2);
  • Initialize your variables. Uninitialized variables have undefined contents. I've wasted a lot of time trying to track down bugs that result from uninitialized variables. The debugger we use at work initializes your variables, so bugs that result from uninitialized variables cannot be reproduced in the debugger! Try tracking those bugs down! ;-)
  • You need to learn Object-Oriented programming if you want to be a good C++ programmer. What you have here is structured programming that happens to use a C++ compiler! ;-) OO may be further down the road in your learning experience, however.
  • Take pride in writing beautiful code! Think of yourself as a craftsman.

Here's your code refactored:
Code:
#include <iostream>
#include <cstring>
#include <fstream>
#include <string>            
#include <stdio.h>
#include <iomanip>

using namespace std;

struct Person
{
   char firstName[80];
   char lastName[80];
};

struct Video
{               
   char title[80];
   Person director;
   Person stars[80];
   int movieLength;
   int howMany; // How many what???
};

void addVideo(int& numVideos, Video videos[]);
void listVideos(int numVideos, Video videos[]); 
void searchList(int numVideos, Video videos[]);
void showMenu(int numVideos);
void readDataFile(int& numVideos, Video videos[]);
void saveToFile(int numVideos, Video videos[]);
void userChoice(char& choice);
void deleteVideo(int& numVideos, Video videos[]);
void quitMessage();

int main()
{
   int      numVideos = 0;
   char     choice = ' '; 
   Video    videos[50];

   readDataFile(numVideos, videos) ;

   do
   {
      showMenu(numVideos);
      userChoice(choice) ;

      cout << "What is your choice (A,L,D,S,Q)? ";
      cin >> choice;
      choice = toupper(choice);

      switch (choice) 				      	
      {                                                       
      case 'A':
         addVideo(numVideos, videos);
         saveToFile(numVideos, videos);
         cout << "Number of videos in main after Add: ";
         cout << numVideos << endl;                 
         break;
      case 'L':
         listVideos(numVideos, videos);
         break;
      case 'D':
         deleteVideo(numVideos, videos);
         saveToFile(numVideos, videos);
         break;
      case 'S':
         searchList(numVideos, videos);
         break;
      case 'Q':
         break;
      default:
         cout << "Error in choice.  Please try again."  << endl;
      }

   } while (choice != 'Q');

   quitMessage();
   return 0;

}


/******************************************************************************/

void addVideo(int& numVideos, Video videos[]){}
void listVideos(int numVideos, Video videos[]){} 
void searchList(int numVideos, Video videos[]){}
void showMenu(int numVideos){}

void readDataFile(int& numVideos, Video videos[])
{
    int lengthOfMovie = 0;
    int howMany = 0; // How many what?
    ifstream videosDB;

    videosDB.open("videosdb.dat");

    /* Whatever you had going on after this... */

    videosDB.close();
}

void saveToFile(int numVideos, Video videos[]){}
void userChoice(char& choice){}
void deleteVideo(int& numVideos, Video videos[]){}
void quitMessage(){}

Last edited by eric.r.turner; 05-16-2004 at 01:06 PM.
 
Old 05-16-2004, 05:35 PM   #9
bru
Member
 
Registered: Sep 2003
Location: South Carolina
Distribution: Ubuntu, CentOS, BT4, Debian
Posts: 132

Original Poster
Rep: Reputation: 15
eric.r.turner thanks man, the reason my code sucks is the fact that I'm still learning C++ I know C++ is OOP but I need to learn the basics of the language before I can code with it like a pro. But again thanks for the help with the code!

P.S. I'M:
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
First kernel compile complete only a couple errors MustangCSA Slackware 7 05-15-2004 07:54 AM
couple of problems with mounting CDs and disk 'input/output' errors. can anyone help? darksmiley Linux - General 5 01-24-2004 09:28 PM
built computer and couple errors degraffenried13 Linux - General 7 01-08-2004 12:46 PM
Gimp-1.2.3 'make' reports syntax errors GabeF Linux - Software 2 06-11-2003 08:29 PM
declaration syntax errors with KYLIX rklosinski Programming 1 11-28-2002 01:49 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration