array of struct function not working

Please don't give me code - this is an assignment. I need help determining testing this as I am not getting any compiler errors, but I know something isn't right due to some "testing couts" not working. Please just point me to where to look to fix the error/s?

Here is my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>

using namespace std;

void openFile(ifstream&, string);
void countL(ifstream&);

int main()  { 

string fileName;	//input: name of text file
string sentence;
ifstream ins;

inf.close();
inf.clear();

while (!inf.eof()){

      getline(inf, sentence);


return 0 ;
}


It is working in the sense that it goes through the first two functions, but after that, I am not getting anything to display.

Thanks in advance.
Last edited on
Let consider your program step by step.

Why did you declare openFile with the second parameter if you pass nothing to it ?

void openFile(ifstream&, string);

1
2
3
4
5
string fileName;	//input: name of text file

....
//insert openFile function
openFile(inf, fileName);  // <== what is the meaning of that argument? 
LOL - well I started to write about how I was passing the fileName to the function and realized I am in fact, NOT passing the fileName to the function.

Correction should be:
1
2
3
4
5
6
7
void openFile(ifstream&) // declaration
... other code
openFile(inf);  //call
...other code
void openFile(ifstream& inf) {     //definition
         function code.... blah blah
}


I just compiled it and it gave me this:

File is open.
Number of Lines: 30
Number of Letters: 1003
Segmentation Fault (core dumped)
Topic archived. No new replies allowed.