ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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.
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.
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!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.