Thread: Borland to Visual Studio

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    52

    Borland to Visual Studio

    Hello I am having problems getting this code to work in VS after it worked fine in Borland... I think it has somethign to do with the header files.... Actually I am sure it is I keep getting errors from them

    Thanks

    Code:
    
    #pragma hdrstop
    
    //---------------------------------------------------------------------------
    #include<iostream.h>
    #include<stdlib.h>
    #include<fstream.h>
    #include<math.h>
    #pragma argsused
    ////////////////////////////////////////////////////////////////////
    // declaring functions
    void GenerateData(int, int *);
    int Hash(int, int *, int, int );
    void Prime(int &, int);
    ////////////////////////////////////////////////////////////////////
    //main fuction
    int main(int argc, char* argv[])
    {
            //declaring local variables
            int *Data;//pointers arrays
            int N = 2, count=0, i, x =15, TableSize;
            ofstream out;
            //open a file for output called data.txt
            out.open("data.txt");
            //if file does not open
            if(out.fail())
            {
                    cout << "Data file did not open";
                    system("pause");
                    exit(0);
            }
            //creat loop to write data to file
            for (i =0; i < x; i++)
            {
                    out << N << " ";
                    N *=2;
            }
            out << endl;
            for (int k =0; k < 2; k++)
            {
                    N =2;
                    for (i =0; i < x; i++)
                    {
                            Data= new int[N];
                            GenerateData(N,Data);
                            Prime(TableSize,N);
                            count = Hash(N,Data,TableSize,k);
                            N*=2;
                            out << count << " ";
                            delete [] Data;
                    }
                    out << endl;
            }
            //close data.text file
            out.close();
    
            system ("pause");
            return 0;
    }//end of main function
    ////////////////////////////////////////////////////////////////
    void Prime(int &TS, int N)
    {
            int EndNum, StartNum, Remainder;
            bool NotPrime=false;
            TS = 2*N +1;
            EndNum = ceil( pow(TS,.5)) +1;
            while (1)
            {
                    for (StartNum=2; StartNum <= EndNum; StartNum++)
                    {
                     Remainder = TS % StartNum;
                     if (Remainder == 0)
                     {
                            NotPrime = true;
                            break;
                     }
                    }
                    if (NotPrime == true)
                        {
                            TS++;
                            EndNum = ceil( pow(TS,.5)) + 1;
                            NotPrime = false;
                        }
                        else break;
    
            }
    }
    ////////////////////////////////////////////////////////////////
    //generating data and putting them in the arrays.
    void GenerateData(int n, int *Data)
    {
            double sum;
            //loop n times to generate data in the the arrays a,b,c from 0 to 999
            for (int i =0; i<n; i++)
            {
                    sum = 0;
                    for(int j =0; j < 5; j++)
                    {
                            sum = (double)(rand()%26)*pow(26.,j) + sum;
                    }
                    Data[i] = sum;
            }
    }//end of GenerateData fuciton
    /////////////////////////////////////////////////////////////////
    int Hash(int n, int *Data,int TS, int k)
    {
            int *HashData;
            int counter = 0, Start, Index, i;
            HashData = new int[TS];
            for (Start=0; Start<TS; Start++)
            {
                    HashData[Start] = -1;
            }//end of for loop
            if (k == 0)
            {
                    //linear hashing
    
                    for (Start=0; Start < n; Start++)
                    {
                            Index = Data[Start] % TS;
                            if(HashData[Index] == -1)
                            {
                                    HashData[Index] = Data[Start];
                                    counter++;
                            }//end if
                            else
                            {
                                    Index++;
                                    while(1)
                                    {
                                            counter++;
                                            if(HashData[Index % TS] == -1)
                                            {
                                                    HashData[Index % TS] = Data[Start];
                                                    break;
                                            }
                                            else
                                                    Index++;
    
                                    }//end of while loop
                            }//end of else
    
                    }//end of for loop
                    delete [] HashData;
            }//end of if statement
    
            else
            {
                    //Quadratic Hashing
                    for (Start=0; Start < n; Start++)
                    {
                            Index = Data[Start] % TS;
                            if(HashData[Index] == -1)
                            {
                                    HashData[Index] = Data[Start];
                                    counter++;
                            }//end of if
                            else
                            {
                                    i =1;
                                    while(1)
                                    {
                                            counter++;
                                            if(HashData[(Index + i*i) % TS] == -1)
                                            {
                                                    HashData[(Index + i*i) % TS] = Data[Start];
                                                    break;
                                            }
                                            else
                                                    i++;
    
                                    }
                            }//end of else
    
                    }//end of for loop
                    delete [] HashData;                
            }
            return (counter);
    }
    //---------------------------------------------------------------------------

  2. #2
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    first when you say "it's giving me errors" try to be a bit more specific!

    but I suspect the problem is here.
    Quote Originally Posted by Halo
    Code:
    #include<iostream.h>
    #include<stdlib.h>
    #include<fstream.h>
    #include<math.h>
    this is non-standard C++. the correct code is
    Code:
    #include<iostream>
    #include<cstdlib>
    #include<fstream>
    #include<cmath>
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    52
    Okay wellI fixed the problem with the headers and a way they make you use the ceil function however I get a crazy error at the end

    Linking...
    LIBCD.lib(wincrt0.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function _WinMainCRTStartup
    Debug/Lab2.exe : fatal error LNK1120: 1 unresolved externals

    Anyone know how to fix this ? Here is the updated code.

    Code:
    #include "stdafx.h"
    #pragma hdrstop
    #include <iostream>
    #include <stdlib.h>
    #include <fstream>
    #include <math.h>
    #include <stdio.h>
    #pragma argsused
    using namespace std;
    
    // declaring functions
    void GenerateData(int, int *);
    int Hash(int, int *, int, int );
    void Prime(int &, int);
    
    int main(int argc, char* argv[])//meat and potatoes
    {
            //declaring local variables
            int *Data;//pointers arrays
            int N = 2, count=0, i, x =15, TableSize;
            ofstream out;
            //open a file for output called data.txt
            out.open("data.txt");
            //if file does not open
            if(out.fail())
            {
                    cout << "Data file did not open";
                    system("pause");
                    exit(0);
            }
            //creat loop to write data to file
            for (i =0; i < x; i++)
            {
                    out << N << " ";
                    N *=2;
            }
            out << endl;
            for (int k =0; k < 2; k++)
            {
                    N =2;
                    for (i =0; i < x; i++)
                    {
                            Data= new int[N];
                            GenerateData(N,Data);
                            Prime(TableSize,N);
                            count = Hash(N,Data,TableSize,k);
                            N*=2;
                            out << count << " ";
                            delete [] Data;
                    }
                    out << endl;
            }
            //close data.text file
            out.close();
    
            system ("pause");
            return 0;
    }
    
    void Prime(int &TS, int N)
    {
            int EndNum, StartNum, Remainder;
            bool NotPrime=false;
            TS = 2*N +1;
            EndNum = ceil((double)pow((double)TS,.5)) +1;
            while (1)
            {
                    for (StartNum=2; StartNum <= EndNum; StartNum++)
                    {
                     Remainder = TS % StartNum;
                     if (Remainder == 0)
                     {
                            NotPrime = true;
                            break;
                     }
                    }
                    if (NotPrime == true)
                        {
                            TS++;
                            EndNum = ceil((double)pow((double) TS,.5)) + 1;
                            NotPrime = false;
                        }
                        else break;
    
            }
    }
    
    //generating data and putting them in the arrays.
    void GenerateData(int n, int *Data)
    {
            double sum;
            //loop n times to generate data in the the arrays a,b,c from 0 to 999
            for (int i =0; i<n; i++)
            {
                    sum = 0;
                    for(int j =0; j < 5; j++)
                    {
                            sum = (double)(rand()%26)*pow(26.,j) + sum;
                    }
                    Data[i] = sum;
            }
    }//end of GenerateData fuciton
    
    int Hash(int n, int *Data,int TS, int k)
    {
            int *HashData;
            int counter = 0, Start, Index, i;
            HashData = new int[TS];
            for (Start=0; Start<TS; Start++)
            {
                    HashData[Start] = -1;
            }//end of for loop
            if (k == 0)
            {
                    //linear hashing
    
                    for (Start=0; Start < n; Start++)
                    {
                            Index = Data[Start] % TS;
                            if(HashData[Index] == -1)
                            {
                                    HashData[Index] = Data[Start];
                                    counter++;
                            }//end if
                            else
                            {
                                    Index++;
                                    while(1)
                                    {
                                            counter++;
                                            if(HashData[Index % TS] == -1)
                                            {
                                                    HashData[Index % TS] = Data[Start];
                                                    break;
                                            }
                                            else
                                                    Index++;
    
                                    }//end of while loop
                            }//end of else
    
                    }//end of for loop
                    delete [] HashData;
            }//end of if statement
    
            else
            {
                    //Quadratic Hashing
                    for (Start=0; Start < n; Start++)
                    {
                            Index = Data[Start] % TS;
                            if(HashData[Index] == -1)
                            {
                                    HashData[Index] = Data[Start];
                                    counter++;
                            }//end of if
                            else
                            {
                                    i =1;
                                    while(1)
                                    {
                                            counter++;
                                            if(HashData[(Index + i*i) % TS] == -1)
                                            {
                                                    HashData[(Index + i*i) % TS] = Data[Start];
                                                    break;
                                            }
                                            else
                                                    i++;
    
                                    }
                            }//end of else
    
                    }//end of for loop
                    delete [] HashData;                
            }
            return (counter);
    }

  4. #4
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    The error doesn't have anything to do with your code. You need to make a Win32 Console Application. My guess it that you created a Win32 Application and the compiler is expecting to see Win Main, when it needs to be looking for int main

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    52
    Amazing... Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM