0

I have been following the programming abstractions course on Stanford online

Here is the link The assignments use various Stanford libraries like "genlib.h", "simpio.h" ... and so on.

I included all the header files under my project properties -> Additional Include directories.

However when I compile the program, it throws below

error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup

This is my code below from the 1st warmup assignment

which can be found here

/*
 * Program: warmup.cpp
 * --------------------
 * Program used to generate a hash code based on user's name.
 * As given, this code has two compiler errors you need to track down 
 * and fix in order to get the program up and running.
 *
 * jzelenski Thu Apr  1 12:27:53 PST 2004
 */
#include <iostream>
#include <istream>
#include "genlib.h"
#include <string.h>

#define MAX_HASH_CODE 10000 // Upper bound for hash codes generated by program

/* Function prototypes */

int Hash(string s, int maxCode);
/*
 * Function: Hash
 * Usage: hash_number = Hash(key, max_hash);
 * -----------------------------------------
 * This function takes the key and uses it to derive a hash code,
 * which is an integer in the range [0, maxCode - 1].  The hash
 * code is computed using a method called linear congruence.
 */
#define Multiplier -1664117991L     // Multiplier used in Hash function

int Hash(string s, int maxCode)
{
    unsigned long hashcode = 0;
    for (int i = 0; i < s.length(); i++) 
        hashcode = hashcode * Multiplier + s[i];
   return (hashcode % maxCode);
}

int main ()
{
    string name = "abc";
    cout << "Please enter your name: ";
    int hashcode = Hash(name, MAX_HASH_CODE);
    cout << "The hash code for your name is " << hashcode << "." <<endl;
    return 0;
}

I am using VS 2012. Does this error have to do anything with not including the .lib file or .cpp file? I remember doing this for other c++ libraries and adding the .lib files under the additional dependencies under Linker -> Input. But I don't have access to any of the .lib files. Just the .h and .cpp files.

I need this to be fixed so that I can proceed with other assignments. Any help would be grateful. Thanks!

Htlcs
  • 545
  • 3
  • 13
  • 26

0 Answers0