Please find and correct the error in my c++ program. "Linker Error: Undefined symbol


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 10 of 10

Thread: Please find and correct the error in my c++ program. "Linker Error: Undefined symbol

Hybrid View

  1. #1
    Join Date
    Feb 2009
    Posts
    7

    Red face 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::output()
    {
    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.

  2. #2
    Join Date
    Feb 2009
    Posts
    7

    Cool I found the error and corrected it.

    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();
    }

  3. #3
    Join Date
    Nov 2003
    Posts
    4,118
    Good. That said, you really want to replace the outdated
    #include<fstream.h>
    #include<iostream.h>
    with
    #include<fstream>
    #include<iostream>
    though. Also, main should return int, not void. The code as-is might not compile with new compilers unless fixed.
    Danny Kalev

  4. #4
    Join Date
    Feb 2009
    Posts
    7
    I still have another problem. That is when the while loop asks continue(y/n)
    When i enter n it just stuck there.

  5. #5
    Join Date
    Nov 2003
    Posts
    4,118
    you should replace the type of ch from char to string or at least a char array.
    Danny Kalev

  6. #6
    Join Date
    Feb 2009
    Posts
    7
    ch is used to get 2 values input y or n. Can you correct the program please.

  7. #7
    Join Date
    Feb 2009
    Posts
    7
    I have correted 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();
    }

  8. #8
    Join Date
    Feb 2009
    Posts
    7
    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();
     }

  9. #9
    Join Date
    Nov 2003
    Posts
    4,118
    You need to check the status of every file operation: make sure that the open() call has succeeded before you move on to write() or read().
    Also, make sure that you open the file in binary mode. Also decide whether you want to always to overwrite the current file content with write() or whether you wish to append new data after existing data (use ios::ate for that).
    Finally, as said earlier, you need to change the type of ch to a char array because pressing 'y' and then Enter write two characters, not one, to the standard input, which is probably why you're getting erratic program behavior.
    Danny Kalev

  10. #10
    Join Date
    Feb 2009
    Posts
    7
    At last my program to transfer content of one file to another. Again thanks. Here is the full program for further reference to other users.

    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();
    }

Similar Threads

  1. Replies: 3
    Last Post: 04-26-2006, 05:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center