• Register
1 vote
23 views

Problem:

I wrote the following subclass for my main program:

#include <stdio.h>
#include <stdlib.h>
#include "function.h"

#define READFILE "r"
#define WRITEFILE "w"
#define WORDARRAYSIZE 16
#define MAXIMUMWORDCHARACTERS 15

void CreateWordList (char inputFileName [ ])
{
   FILE* inputFile;
   
   inputFile = fopen (inputFileName, WRITEFILE);
   
   if (inputFile == NULL)
   {
      fprintf(stderr, "Error - Cannot open %s for reading!\n", 
	      inputFileName);
      
      exit (-1);
   }
}



int CountNumberOfWords (FILE* inputFile)
{
   int wordCounter = 0;
   char wordArray [WORDARRAYSIZE];
   
   while (fgets (wordArray, WORDARRAYSIZE, inputFile) != NULL )
   {
      wordCounter++;
   }
   
   return wordCounter;
}

Basically, I'm just trying to count the number of words in a data file, where you have no idea how many words are actually there. The first function has not been completed and is completely useless in its remedial stages, but somewhere, the following error occurs, “Undefined reference to main c++”

12 7 7
15,250 points

1 Answer

1 vote

Solution:

It seems like you are a pretty advance programmer, unfortunately, you did a basic level mistake in your code.

The main() function is the life of a c++ program and I didn’t find any main() in your program. Put the main()

int main()
{
  return 0;
}

 

 in your code on the proper section and give it another try. It should work fine for sure.
Thanks.

13 9 6
94,240 points

Related questions

1 vote
1 answer 580 views
580 views
Problem: I am very new to Programming. I want to compile my recently written program it is called myes3 but when I try to write from the terminal: gcc myes3.c -o myes3 I always face below error message: /usr/lib/gcc/i686-linux-gnu/4.4.5/../../. ... collect2: ld returned 1 exit status I have very elementary knowledge of programming so unable to fix above error. Please help me in fixing above error.
asked May 27 Martin K 6.6k points
0 votes
1 answer 21 views
21 views
Problem: I am working on functions in C++. I am facing the above mentioned error while I am trying to run the following program: #include <iostream> using namespace std; int main() { cout<<func(4); } int func(int number) { return number; } I have no idea about the error. Why this error is being triggered and how can I resolve this issue?
asked Nov 10 Sheeza 3.6k points
0 votes
1 answer 26 views
26 views
Problem: I have been working on classes in C++ for about a few days. I am learning constructors with parameters. I was trying to run the following program in which I have declared two constructors, one without parameters and other with one parameter. The problem ... The program works perfectly when I comment out the error-generating statement. I have no idea what I am doing wrong. Please Help.
asked Nov 9 Sheeza 3.6k points
0 votes
1 answer 5 views
5 views
Problem: Hi there! I am a newbie and started learning programming recently. While doing programming, as a beginner I encountered many errors but the most rapidly occurring error was &ldquo;C++ requires a type specifier for all declarations&rdquo;. Although, I managed to resolve the error everytime, I want to know why this error is generated and how can I avoid it?
asked Nov 5 Sheeza 3.6k points