Weird Error. Please Help.
Well basically I am supposed to create a program that reads a specific file and counts the words,lines, and paragraphs (Paragraphs are considered to be anything with a full line of blank space inbetween text).
When I run build in Visual C++ it seems as if it compiles just fine, but it won't link.
I get the following error:
error LNK2001: unresolved external symbol "void __cdecl processBlanks(class std::basic_ifstream<char,struct std::char_traits<char> > &,char &,int &)" (?processBlanks@@YAXAAV?$basic_ifstream@DU?$char_t raits@D@std@@@std@@A
ADAAH@Z)
fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Now let me just say that, When I remove the functions from the program it works fine. So my guess is that it has something to do with how I am passing the ifstream to my functions.
Code:
#include <iostream>
#include <fstream>
using namespace std;
void processBlanks(ifstream& Istream,char & ch, int & wordCount);
void copyText(ifstream& Istream,char & ch);
void updateCount(int & totalwordCount, int & wordCount, int & lines, int & paraGraph);
void printTotal(int & totalwordCount, int & lines, int & paraGraph);
//==============================================================================================================================================
//========================================================== Main Function =====================================================================
//==============================================================================================================================================
int main() // begin main function
{
ifstream Istream;
ofstream Ostream; // Change name of Ofstream into Ostream
int lines =0;
int wordCount =0;
int totalwordCount =0;
int paraGraph = 0;
char ch;
// Declaring variables as strings
Istream.open("Yo.txt"); // Opening of the Text document
Ostream.open("word.txt");
Istream.get(ch);
while (Istream != 0) // Process the file (While 1)
{
while (ch != '\n') // Process the line (While 2)
{
processBlanks(Istream,ch,wordCount);
copyText(Istream,ch);
} // EoWhile 2
updateCount(totalwordCount,wordCount,lines,paraGraph);
cout << ch;
Istream.get(ch);
} // EoWhile 1
printTotal(totalwordCount,lines,paraGraph);
Istream.close();
Ostream.close();
return 0;
}
//==============================================================================================================================================
//======================================================= End of Function ======================================================================
//==============================================================================================================================================
//==============================================================================================================================================
//========================================================== processBlank Function =============================================================
//==============================================================================================================================================
void processBlanks(ifstream& Istream,char & ch, int wordCount)
{
while (ch == ' ') // (While 3)
{
cout << ch ;
Istream.get(ch);
}
if (ch != ' ' && ch != '\n')
{
wordCount++;
}
return;
}
//==============================================================================================================================================
//======================================================= End of Function ======================================================================
//==============================================================================================================================================
//==============================================================================================================================================
//========================================================== copyText Function =================================================================
//==============================================================================================================================================
void copyText(ifstream& Istream,char & ch)
{
while (ch != ' ' && ch != '\n') // While 4
{
cout << ch;
Istream.get(ch);
}
return;
}
//==============================================================================================================================================
//======================================================= End of Function ======================================================================
//==============================================================================================================================================
//==============================================================================================================================================
//========================================================== updateCount Function ==============================================================
//==============================================================================================================================================
void updateCount(int & totalwordCount, int & wordCount, int & lines, int & paraGraph)
{
totalwordCount = totalwordCount + wordCount;
lines++;
if (wordCount == 0)
{
paraGraph++;
lines--;
}
wordCount = 0;
return;
}
//==============================================================================================================================================
//======================================================= End of Function ======================================================================
//==============================================================================================================================================
//==============================================================================================================================================
//========================================================== printTotal Function ===============================================================
//==============================================================================================================================================
void printTotal(int & totalwordCount, int & lines, int & paraGraph)
{
cout << "Total Words is equal to " << totalwordCount << endl;
cout << "Total Lines is equal to " << lines << endl;
cout << "Total paragraphs is equal to " << paraGraph << endl;
return;
}
//==============================================================================================================================================
//======================================================= End of Function ======================================================================
//==============================================================================================================================================