I keep getting an error that says Segmentation Fault. Online it says that it's a very vague error message, therefore it is hard to figure out what the problem is. Can anyone maybe take a look and see if they can find what might be causing the problem?
//////////////////////////////////////
//------- Section 3 Homework Assignment #10
//This program will prompt the user for the name //of an input file. It will count the number of
//words, sentences, capital letters, lower case //letters, consonants, and digits within the file.
//It will also find the longest word in the file.
//After running it, it will list the amounts of
//each and also format the text within the file
//correctly.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
int vowels(int,int,string);
int digits(int,int,string);
int capitals(int,int,string);
int words(int,int,string);
int lowercase(int,int,string);
int sentences(int,int,string);
int main()
{
int word;
int capital;
int lower;
int sentence;
int avgword;
int digit;
int consonant;
int sentencecount;
ifstream infile;
string text;
string line;
int length;
cout << "Enter input file name" << endl;
cin >> text;
infile.open(text.c_str());
infile >> text;
while (!infile.eof())
{
length = text.length();
int space=0;
int i=0;
char ch;
string something;
{
for (i=0; i>=0; i++)
ch = text[i];
if (ch == '\n')
space++;
while (space !=2)
int words(int word,int length,string text)
//Counts the number of words within the file by counting the number of //blank spaces. After every word is counted, wordcount is returned.
{
int wordcount=0;
char ch;
for (int i=0; i<length; i++)
{
ch = text[i];
if (ch == '\n')
{
wordcount++;
}
}
return wordcount;
}
int capitals(int capital,int length,string text) //Counts the number of capital letters with the use of
//isupper.Return capitalcount is passed back after
//every capital letter is counted.
{
char ch;
int capitalcount =0;
for (int i=0; i<length; i++)
{
ch = text[i];
if (isupper(ch))
{
capitalcount++;
}
}
return capitalcount;
}
int lowercase(int lower,int length,string text)
//Counts the number of lowercase letters using //islower. After all lowercase letters is found, //return lowercount is passed back.
{
char ch;
int lowercount =0;
for (int i=0; i<length; i++)
{
ch = text[i];
if (islower(ch))
{
lowercount++;
}
}
return lowercount;
}
int vowels(int consonant,int length,string text)
//Counts the number of consonant letters. If character
//A,E,I,O, and U or a,e,i,o, and u is read,
//1 is added to the counter.
{
int consonantcount =0;
char ch;
for (int i=0; i<length; i++)
ch = text[i];
if (ch == 'A' or ch == 'a' or ch == 'E' or ch == 'e' or ch == 'I' or ch == 'i' or ch == 'O' or ch == 'o' or ch == 'U' or ch == 'u')
{
consonantcount++;
}
return consonantcount;
}
int digits(int digit,int length,string text) //Counts the number of digits using isdigit.
//After all digits are counted, digitcount
//will be returned.
{
char ch;
int digitcount =0;
for (int i =0; i<length; i++)
{
ch = text[i];
if (isdigit(ch))
digitcount++;
{
digitcount++;
}
}
return digitcount;
}
int sentences(int sentencecount,int length,string text)
//Counts the number of sentences. If a period, //exclamation mark, or question mark is read
//one is added to the count.
{
char ch;
int sentence =0;
{
for (int i=0; i<length; i++)
ch = text[i];
if (ch == '.' or ch =='!' or ch == '?')
{
sentence++;
}
}
return sentence;
}