-
February 24th, 2009, 07:02 AM
#1
Please find and correct the error in my c++ program. "Linker Error: Undefined symbol
Please find and correct the error in my c++ program. "Linker Error: Undefined symbol _main in module c0.ASM"
The program is for transfering content of one file to another.
#include<fstream.h>
#include<iostream.h>
#include<conio.h>
class student
{
int rollno;
char name[20];
int tm;
public:
void input();
void transfer();
void output();
}
obj;
void student::input()
{
char ch='y';
ofstream outf;
outf.open("mark.dat");
while(ch=='y')
{
cout<<"Enter rollno, name and mark";
cin>>rollno>>name>>tm;
outf.write((char*)&obj,sizeof(obj));
cout<<"wish to enter more(Y/N)";
cin>>ch;
}
outf.close();
}
void student::transfer()
{
ofstream outf;
ifstream inf;
inf.open("mark.dat");
inf.open("trans.dat");
while(inf)
{
inf.read((char*)&obj,sizeof(obj));
outf.write((char*)&obj,sizeof(obj));
}
outf.close();
inf.close();
}
void student:utput()
{
ifstream inf;
inf.open("trans.dat");
while(inf)
{
inf.read((char*)&obj,sizeof(obj));
cout<<"Rollno"<<rollno;
cout<<"Name"<<name;
cout<<"Total"<<tm;
}
getch();
inf.close();
}
The error i get is
compiling 10.cpp
linking ...\OUTPUT\10.EXE
.Linker Error: Undefined symbol _main in module c0.ASM
I think the error is due to the missing of void main. But i don't know where i should put it.
-
February 24th, 2009, 07:13 AM
#2
Re: Please find and correct the error in my c++ program. "Linker Error: Undefined sym
Looks like you haven't defined the main function which is the entry point for the program.
-
February 24th, 2009, 07:24 AM
#3
Re: Please find and correct the error in my c++ program. "Linker Error: Undefined sym
Please add main function and correct the program.
-
February 24th, 2009, 07:56 AM
#4
Re: Please find and correct the error in my c++ program. "Linker Error: Undefined sym
think i got this from my friend
void main()
{
student obj;
obj.input();
obj.transfer();
obj.output();
getch();
}
He told to put it at last but hwo do i do that?
-
February 24th, 2009, 08:06 AM
#5
Re: Please find and correct the error in my c++ program. "Linker Error: Undefined sym
I found the error and corrected it.
#include<fstream.h>
#include<iostream.h>
#include<conio.h>
class student
{
int rollno;
char name[20];
int tm;
public:
void input();
void transfer();
void output();
}
obj;
void student::input()
{
char ch='y';
ofstream outf;
outf.open("mark.dat");
while(ch=='y')
{
cout<<"Enter rollno, name and mark";
cin>>rollno>>name>>tm;
outf.write((char*)&obj,sizeof(obj));
cout<<"wish to enter more(Y/N)";
cin>>ch;
}
outf.close();
}
void student::transfer()
{
ofstream outf;
ifstream inf;
inf.open("mark.dat");
inf.open("trans.dat");
while(inf)
{
inf.read((char*)&obj,sizeof(obj));
outf.write((char*)&obj,sizeof(obj));
}
outf.close();
inf.close();
}
void student:utput()
{
ifstream inf;
inf.open("trans.dat");
while(inf)
{
inf.read((char*)&obj,sizeof(obj));
cout<<"Rollno"<<rollno;
cout<<"Name"<<name;
cout<<"Total"<<tm;
}
inf.close();
}
void main()
{
student obj;
obj.input();
obj.transfer();
obj.output();
getch();
}
-
February 24th, 2009, 08:15 AM
#6
Re: Please find and correct the error in my c++ program. "Linker Error: Undefined sym
And by doing that you've learned a lot more than you had just copying from a forum post.
By the way, main always returns an int i.e. it should be int main (even though the compiler also accepts the current version)
-
February 24th, 2009, 10:01 AM
#7
Re: Please find and correct the error in my c++ program. "Linker Error: Undefined sym
I still have another problem. That is when the while loop asks continue(y/n)
When i enter n it just stuck there.
-
February 24th, 2009, 11:01 PM
#8
Re: Please find and correct the error in my c++ program. "Linker Error: Undefined sym
I have corrected almost.
Please correct the error in my program. When i run the program on turbo c++ 3, it output 3 times. Also When i enter more than 1 entry only the last entry is outputted. Also it is outputted 3 times.
#include<fstream.h>
#include<iostream.h>
#include<conio.h>
class student
{
int rollno;
char name[20];
int tm;
public:
void input();
void transfer();
void output();
}
obj;
void student::input()
{
char ch='y';
ofstream outf;
outf.open("mark.dat");
while(ch=='y')
{
cout<<"Enter rollno, name and mark";
cin>>rollno>>name>>tm;
outf.write((char*)&obj,sizeof(obj));
cout<<"Wish to enter more(Y/N)?\n";
cin>>ch;
}
outf.close();
}
void student::transfer()
{
ofstream outf;
ifstream inf;
inf.open("mark.dat");
outf.open("trans.dat");
while(inf)
{
inf.read((char*)&obj,sizeof(obj));
outf.write((char*)&obj,sizeof(obj));
}
outf.close();
inf.close();
}
void student:utput()
{
ifstream inf;
inf.open("trans.dat");
while(inf)
{
inf.read((char*)&obj,sizeof(obj));
cout<<"\nRollno "<<rollno;
cout<<"\nName "<<name;
cout<<"\nTotal "<<tm;
}
inf.close();
}
void main()
{
clrscr();
student obj;
obj.input();
obj.transfer();
obj.output();
getch();
}
-
February 25th, 2009, 06:19 AM
#9
Re: Please find and correct the error in my c++ program. "Linker Error: Undefined sym
I have tried to intend it.
Thank you very much for taking time. I am from India and here we learn about only basics of c++ and our syllabus is based on turbo c++ 3. So i use turbo c++ and i don't know much about c++ programing. So i cannot implement instructions you give on modern c++.
I tried new changes. But i still have some little problems. The program is to transfer content of one file to another. When i input only one entry, the program works. But when more than one entry is used it out puts only 1 or 2. Kindly please correct the problem.
Here is the new code by correcting the previous errors.
Code:
#include<fstream.h>
#include<iostream.h>
#include<conio.h>
class student
{
int rollno;
char name[20];
int tm;
public:
void input();
void transfer();
void output();
};
void student::input()
{
char ch='y';
ofstream outf;
outf.open("mark.dat");
while(ch=='y')
{
cout<<"Enter rollno, name and mark\n";
cin>>rollno>>name>>tm;
outf.write((char*)this,sizeof(student));
cout<<"Wish to enter more(Y/N)?\n";
cin>>ch;
}
outf.close();
}
void student::transfer()
{
ofstream outf;
ifstream inf;
inf.open("mark.dat");
outf.open("trans.dat");
while( inf.read(( char* )this,sizeof(student)))
{
outf.write(( char* )this,sizeof( student ) );
}
outf.close();
inf.close();
}
void student::output()
{
ifstream inf;
inf.open("trans.dat");
while (inf.read((char*)this, sizeof(student)))
{
inf.read(( char* )this,sizeof( student ) );
cout<<"\nRollno "<<rollno;
cout<<"\tName "<<name;
cout<<"\tTotal "<<tm<<'\n';
}
inf.close();
}
void main()
{
clrscr();
student obj;
obj.input();
obj.transfer();
obj.output();
getch();
}
-
February 25th, 2009, 10:08 AM
#10
Re: Please find and correct the error in my c++ program. "Linker Error: Undefined sym
Originally Posted by tharun518
Kindly please correct the problem.
Generally, when a program does something you don't want or expect, you debug it (as opposed to dumping it on a programming forum). A simple debugging technique is using cout to show the state of variables at various points in your program. Like:
Code:
std::cout << "at this point in the program variable x is" << x << std::endl;
Even better, learn how to use the debugger that comes with your development environment.
-
February 25th, 2009, 12:48 PM
#11
Re: Please find and correct the error in my c++ program. "Linker Error: Undefined sym
Originally Posted by tharun518
I have tried to intend it.
Thank you very much for taking time. I am from India and here we learn about only basics of c++ and our syllabus is based on turbo c++ 3. So i use turbo c++ and i don't know much about c++ programing. So i cannot implement instructions you give on modern c++.
"Modern" C++ is over 10 years old. I am surprised you are using something more than 10 years old (closer to 20 years old), especially when there are free C++ compilers (gcc is one of them) that use modern C++ syntax.
What you're learning now is not what C++ is today or has been for 10 years now, and whoever mandated that this compiler be used is doing you more harm than good. For example, none of those headers (<iostream.h>, <fstream.h>, etc.) exist on many C++ compilers, since they are obsolete.
Regards,
Paul McKenzie
-
February 25th, 2009, 01:29 PM
#12
Re: Please find and correct the error in my c++ program. "Linker Error: Undefined sym
To add to what Paul just piointed out....
Many employeers have specific questions in the interview process to locate people who have learned using obsolete tools. These will usually cause the person to be immediately removed from consideration (even for entry level jobs).
So what you are being taught can actually HURT your career. Find out WHY your professor is teaching material that will do more harm than good. If at all possible switch out of the class or even out of the school.
Remember it is YOUR future, and YOU have to take responsibility for it.
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
February 25th, 2009, 09:04 PM
#13
Re: Please find and correct the error in my c++ program. "Linker Error: Undefined sym
I got all the program correctly here is it. Our syllabus(school) prescribes this c++. So i am using it.
Code:
#include<fstream.h>
#include<iostream.h>
#include<conio.h>
class student
{
int rollno;
char name[20];
int tm;
public:
void input();
void transfer();
void output();
};
void student::input()
{
char ch='y';
ofstream outf;
outf.open("mark.dat");
while(ch=='y')
{
cout<<"Enter rollno, name and mark\n";
cin>>rollno>>name>>tm;
outf.write((char*)this,sizeof(student));
cout<<"Wish to enter more(Y/N)?\n";
cin>>ch;
}
outf.close();
}
void student::transfer()
{
ofstream outf;
ifstream inf;
inf.open("mark.dat");
outf.open("trans.dat");
while( inf.read(( char* )this,sizeof(student)))
{
outf.write(( char* )this,sizeof( student ) );
}
outf.close();
inf.close();
}
void student::output()
{
ifstream inf;
inf.open("trans.dat");
while (inf.read((char*)this, sizeof(student)))
{
cout<<"\nRollno "<<rollno;
cout<<"\tName "<<name;
cout<<"\tTotal "<<tm<<'\n';
}
inf.close();
}
void main()
{
clrscr();
student obj;
obj.input();
obj.transfer();
obj.output();
getch();
}
-
February 25th, 2009, 09:12 PM
#14
Re: Please find and correct the error in my c++ program. "Linker Error: Undefined sym
Originally Posted by tharun518
I got all the program correctly here is it. Our syllabus(school) prescribes this c++. So i am using it.
Whatever that school is, it should be stripped of its certification to teach C++ programming. At the very least, if you're serious, you should get the free g++ compiler and write the code correctly.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; February 25th, 2009 at 09:15 PM.
-
February 25th, 2009, 09:17 PM
#15
Re: Please find and correct the error in my c++ program. "Linker Error: Undefined sym
Originally Posted by tharun518
I got all the program correctly here is it. Our syllabus(school) prescribes this c++. So i am using it.
Blindly following someone or something once it has been pointed out that it is incorrect (by existing standards) and will be harmful to your future is not a sane decision.
That is not meant to be "mean" or "rude", but is a simple statement of fact.
Ask your instructor at the next class session the following question?
"If I show an assignment to a prospective employeer, that you have given me an A on, and the result is that I am blackballed from the industry; will you (the professor or school) provide me an income for the rest of my life?"
If the answer is YES, then by all means continue in the current direction. But if either of the following are true, then seriously reconsider the "Value" you are getting from the school...
a) The professor does not know (or care) that the material that is being taught is WRONG.
b) The professor knows that it is wrong, but is continuing to teach it, knowing that it will harm your career.
You position in life is very likely to be influenced for many many years depending on how you handle this.
Good Luck.
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|