Error "Segmentation fault"

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)

cout << ch << endl;
}
{
word =words(word,length,text);
sentence = sentences(sentencecount,length,text);
avgword = (word/sentence);
}
infile >> text;
}
cout << fixed << showpoint << setprecision(3);
cout << setfill('0');
cout << "Words:" << setw(30) << word << endl;
cout << "Capital Letters:" << setw(30) << capital << endl;
cout << "Lowercase Letters:" << setw(30) << lower << endl;
cout << "Consonants:" << setw(30) << consonant << endl;
cout << "Digits:" << setw(30) << digit << endl;
cout << "Sentences:" << setw(30) << sentence << endl;
cout << "Average words per sentence:" << setw(30) << avgword<< endl;

return 0;
}

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;
}




/////////////////////////////////////////////////
This line is a guarantee for a crash

1
2
for (i=0; i>=0; i++)
ch = text[i];


please use code tags. This way it's nearly impossible to read
Topic archived. No new replies allowed.