• Register
1 vote
41 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

Please log in or register to answer this question.

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,260 points

Related questions

0 votes
1 answer 6 views
6 views
Question: I'm working on a simple class List, but when compiling the header and cpp file, I get the error: undefined reference to `main' What am I doing wrong, and how could I fix this? Here is the list.h file that has simple headers: list.h #ifndef LIST_H #define LIST_H ... "using namespace std" and how to include , but I can't figure out how to get these errors to go away. What is causing them?
asked Apr 14 Atik03 26.5k points
0 votes
1 answer 25 views
25 views
Problem: how to fix undefined reference to main c++
asked Feb 15 jasimchaudary 1.5k points
0 votes
1 answer 5 views
5 views
Problem: I don ' t know why this happening : #include <iostream> #include "h8.h" using namespace std; int main() { char sentence[MAX_SENTENCE_LENGTH]; char writeTo[] = "output.txt"; int distanceTo,likePosition, length, numWords; cout << "ENTER A SENTENCE! "; cin. ... ); The error exactly is: undefined reference to 'insertLike(char const*, int, int, char const*)' collect2: ld returned 1 exit status
asked Apr 12 ochena 23.3k points
0 votes
1 answer 30 views
30 views
Problem: Apart from the system and semantic errors and exceptions that occur from time to time, we also get other critical errors that affect the running of programs. These errors mostly occur towards the end of the program at runtime. Sometimes the program gives proper output and then the error occurs.
asked Dec 23, 2020 Mashhoodch 13k points
0 votes
1 answer 5 views
5 views
Problem: I need help in resolving this problem: int main vs void main c++
asked Apr 9 rakib1 51.5k points
0 votes
1 answer 8 views
8 views
Problem: I need someone to understand this problem and find out the solution of error: could not find or load main class undefined.
asked Mar 27 ashik 14.6k points
0 votes
1 answer 4 views
4 views
Problem: What the reason undefined reference to pthread_create' c++?
asked Apr 13 jamuna1 30.2k points
0 votes
1 answer 53 views
53 views
Problem I am getting an error that is undefined reference to a constructor. Program.cc #include "words.h" #include <string>   using namespace std;   int main(int argc, char* argv[]){   string file = "words.txt";   Words w1(file);     return 0; } Word ... then print it out. I know there is something missing in this code.so please provide me the correct solution of this will be appreciative for me
asked Dec 22, 2020 chris jordan 2.4k points
0 votes
1 answer 3 views
3 views
Problem: Can you answer me undefined reference to `pthread_create'
asked Apr 13 jamuna1 30.2k points
0 votes
0 answers 2 views
2 views
Problem: Solve me the some way to undefined reference to pthread_create
asked Apr 13 jamuna1 30.2k points