0

Hello everyone I have been working on my lab for a few days now and I think I am close to completion. However when I go to build my program I keep getting the errors unresolved external symbol main reference in function int cdecl. Its also giving me the error of 1 unresolved externals. I am not sure what this means since I am new to writing in C++ and any help would be greatly appreciated.

Here is what I have so far

enter code here 

#include <iostream>
#include <fstream>
#include <string>

using namespace std;
void menu(void);
void writeData(void);
void readData(void);
string * split(string, char);

const char FileName[] = "TestAddress.txt"; //File name from where to read the characters


int _tmain()
{
    menu();
    return 0;

}

void menu(void) {  //Display main menu and call relevant functions

    char input;

    while (1)
    {
        cout << endl;
        cout << "|---------------------MENU----------------------------|" << endl; //Menu display with style
        cout << "|      (A)ppend Records, (S)how Records, (E)xit       |" << endl; //3 options that can be selected
        cout << "|-----------------------------------------------------|";

        cout << endl << endl;
        cin >> input;

        if (input == 'A' || input == 'a')
            writeData();//Append data to the file
        else if (input == 'S' || input == 's')
            readData(); //Read records from the file and display
        else if (input == 'E' || input == 'e')
            exit(0);// Exit application
        else
            cout << endl << "Invalid Input!!! Please try again." << endl << endl; //In case of invalid input, menu will be displayed again
    }
}//end menu
void writeData(void) {//Append data to the file
    string Name, Street, City, State, ZipCode, input;

    fstream outputFile;
    outputFile.open(FileName, fstream::app); //Open the file with append mode

    do {
        cout << endl << endl;
        cout << "Please enter Name:" << endl;
        cin >> Name;    //Input Name
        cout << endl;

        cout << "Please enter Street:" << endl;
        cin >> Street;//Input Street Address
        cout << endl;

        cout << "Please enter City:" << endl;
        cin >> City; //Input City
        cout << endl;

        cout << "Please enter State:" << endl;
        cin >> State;// Input State
        cout << endl;

        cout << "Please enter ZipCode:" << endl;
        cin >> ZipCode; //Input Zipcode
        cout << endl;
        cout << endl;

        outputFile << Name << "," << Street << "," << City << "," << State << "," << ZipCode << endl; //Write all data to the file

                                                                                                      //Displaying the record which is input recently fromt he user
        cout << endl;  //Displaying heading with style
        cout << "|-----------------------------------------------------|" << endl;
        cout << "|                     Append Records                  |" << endl;
        cout << "|-----------------------------------------------------|" << endl << endl;

        cout << "Name.........." << Name << endl;
        cout << "Street........" << Street << endl;
        cout << "City.........." << City << endl;
        cout << "State........." << State << endl;
        cout << "Zip Code......" << ZipCode << endl;
        cout << endl << endl;

        do {

            cout << "Enter Another Record?(Y/N)" << endl;
            cin >> input;//In case if user wants to enter another rcord
        } while (input != "Y"&& input != "y" && input != "N"&& input != "n"); //Until the user presses 'y' or 'n'

    } while (input == "Y" || input == "y"); //If user wants to add another record continue or else display menu again

    outputFile.close(); //Close file
}//end write data
void readData(void) {//Read records from the file and display
    string  Name, Street, City, State, ZipCode;
    char* line = new char[2000]; //pointing to a vriable that will be having a record detail
    ifstream inputFile;
    int RecordNumber = 1;
    inputFile.open(FileName, fstream::in);//Open the file with read mode

    cout << endl;
    cout << "|-----------------------------------------------------|" << endl; //Heading display with style
    cout << "|                     Show Records                    |" << endl;
    cout << "|-----------------------------------------------------|";
    while (!inputFile.eof())
    {
        inputFile.getline(line, 2000); //Read one record from the file      

        string * fields = split(line, ',');//Split the records based on the prsence of ','

        if (fields[0] == "") //In case of '\n' has encountered
            continue; //Steop processing and continue the loop again
        cout << "" << endl;

        cout << "Record #" << RecordNumber << endl; //Displaying record with style
        cout << "Name.........." << fields[0] << endl;
        cout << "Street........" << fields[1] << endl;
        cout << "City.........." << fields[2] << endl;
        cout << "State........." << fields[3] << endl;
        cout << "Zip Code......" << fields[4] << endl;
        cout << endl << "-------------------------------------------------------" << endl << endl;
        RecordNumber++; //Increment record number
    }
}//end read data
string * split(string theLine, char theDeliminator) {
    //determine how many splits there will be so we can size our array
    int splitCount = 0;
    for (int i = 0; i < theLine.size(); i++) { //Read the whole string (theLine) and count for all ',' encountered
        if (theLine[i] == theDeliminator)
            splitCount++;
    }
    splitCount++; //add one more to the count because there is not an ending comma 
                  //create an array to hold the fields
    string* theFieldArray;
    theFieldArray = new string[splitCount];
    //split the string into seperate fields
    string theField = "";
    int commaCount = 0;

    for (int i = 0; i < theLine.size(); i++) { //read each character and look for the deliminator
        if (theLine[i] != theDeliminator) {
            theField += theLine[i]; //build the field
        }
        else { //the deliminator was hit so save to the field to the array
            theFieldArray[commaCount] = theField; //save the field to the array
            theField = "";
            commaCount++;
        }
    }
    theFieldArray[commaCount] = theField; //the last field is not marked with a comma...

    return theFieldArray;
} //end split
  • 2
    Typo; `int _tmain()` -> `int main()` – NathanOliver Apr 13 '17 at 16:21
  • The `_tmain` function is a Windows-specific extension for WIN32 console applications. For "normal" console applications, as for the rest of the world the standard entry-point into your program is `main`. As any [good beginners book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) would have told you. – Some programmer dude Apr 13 '17 at 16:35
  • Thank you I cannot believe I missed that. Such a foolish mistake. Fixing that error like you said and my program works perfect. – French728 Apr 13 '17 at 18:01

0 Answers0