File pointer problem

I am trying to determine what I am doing wrong, it's giving me an error on line 52 with the fp (file pointer). I know I am missing something but can't put my finger on it. (ignore the brackets inconsistency)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include<iostream>
#include<cctype>
#include<fstream>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
struct Count
{
	 int countChars; //Counts characters
	 int countNW; //counts nonwhite spaces
	 int countAlpha; //counts # of alphabetical letters in use
	 int countDigits; //counts digits
	 int countPunctuation; //counts punctuation
};

int countChars(Count&);
int countNW(Count&);
int countAlpha(Count&);
int countDigits(Count&);
int countPunctuation(Count&);

int main()
{
	string Total_Character;
	string Alphabetic_Character;
	string Punctuation;
	int i; //repeater
	ifstream input;
	ofstream output;
	string fname;

	//Intro
	cout << "Welcome to this program.\n";
	cout << "Please enter text file you use.\n";
	cin >> fname;
        //opening file if correct
        input.open(fname.c_str());
        if(input.fail())
        {
        	cout << "Not a valid filename\n";
                exit(0);
        }
	char line[80];	//number of lines in the file being read
	char delims[]= ",\t\n";	// delimeters: space, ',', tab, return   
	
	while(fgets(line,256,fp))
	{
		printf("lines %d\n", line);
		countChars(Count, line);
		countNW(Count, line);
		countAlpha(Count, line);
		countDigits(Count, line);
		countPunctuation(Count, line);
	}
}
/* Function: countChars
 * Input: characters
 * Output:Counts letters on the line
 * Description: Counts letters in each line
*/ 
int countChar(Counts& Count, char line[])
{
	int c=0; //Repeater
	char letter; //each individual letters in the line
	while(line[c] != "\0")
	{
		input >> letter;
		c++
	}
	return c;
}
/* Function: countNW
 * Input:Spaces and returns
 * Output: Count the number of non white spaces
 * Description: Counts number of non white spaces
*/
int countNW(Counts& countNW, int line[])
{
	int d=0; //Repeater
	char 
	while(line[d] != "\0")
	{
		input >> 
/* Function: countAplha
 * Input:Alphabetical charachters
 * Output:Counts the number of alphabetical characters
 * Description: 
*/
int countAlpha(Counts& countAlpha, int line[])
{
	int e=0; //Repeater
	char
	while(line[e] != "\0")
	{
		input >>
/* Function: countDigits
 * Input:numbers
 * Output:Counts the number of numbers usage
*/
int countDigits(Counts& countDigits, int line[])
{
	int f=0; //
	char
	while(line[f] != "\0" 
	{
		input >>
/* Function: countPunctuation
 * Input:Punctuations
 * Output:
*/
int countPunctuations(Count& countPunctuation, int line[])
{
	int g=0; //repeater
	char
	while (line[g] != "\0"
	{
		input >>


// 1.Does not print out accurate total character count
// 2.Does not print out accurate alphabetic character count
// 3.Does not print out accurate numeric character count
// 4.Does not print out accurate punctuation count
// 5.Does not print out accurate non whitespace character count 
Last edited on
On line 52, you're attempting to call countDigits() while passing two arguments, even though the prototype on line 19 only takes one.
The same can be said about all the function calls from lines 49 - 53.
Last edited on
What about line 46?
Line 46:
 
    while(fgets(line,256,fp))
that is the C file i/o function, header <cstdio>,
but the input was opened at line 37 as a C++ stream, header <fstream>
I'd recommend remove line 5
 
#include<stdio.h> // delete this line 
and just use the C++ approach.

Then change line 46 to:
 
    while (input.getline(line, 256))
and since you specified a length of 256, also change the buffer length at line 43 to agree:
 
    char line[256]; // buffer to hold one line from the input file 
They errors that I have now are.
Code.cpp: In function 'int main()':
Code.cpp:55: error: expected primary-expression before ',' token
Code.cpp:56: error: expected primary-expression before ',' token
Code.cpp:57: error: expected primary-expression before ',' token
Code.cpp:58: error: expected primary-expression before ',' token
Code.cpp:59: error: expected primary-expression before ',' token
Code.cpp: In function 'int countChar(Count&, char*)':
Code.cpp:71: error: ISO C++ forbids comparison between pointer and integer
Code.cpp:73: error: 'input' was not declared in this scope
Code.cpp:75: error: expected ';' before '}' token
Code.cpp: At global scope:
Code.cpp:83: error: 'int countNW' redeclared as different kind of symbol
Code.cpp:23: error: previous declaration of 'int countNW(Count&)'
Code.cpp:83: error: 'Counts' was not declared in this scope
Code.cpp:83: error: expected primary-expression before 'int'
Well, a lot of the code as originally posted was incomplete, so I wouldn't expect it to compile. For example:
100
101
102
103
104
105
106
int countDigits(Counts& countDigits, int line[])
{
	int f=0; //
	char
	while(line[f] != "\0" 
	{
		input >>

Rather than itemise the errors, I've just patched it up so it will at least stand a chance of compiling - but I don't guarantee it will do anything useful at this stage, but it's a start, perhaps.
1
2
3
4
5
6
7
8
9
10
int countDigits(Count& countDigits, char line[])
{
    int f=0;
    
    while (line[f] != '\0') 
    {
	    f++;
    }
    return 0;
}

Actually the while condition could be written this way and mean the same:
 
    while (line[f]) 


These changes apply in a similar fashion throughout the code.
I'm getting this error: 82: error: 'int countNW' redeclared as different kind of symbol.

I'm sorta confused by what they mean by "different kind of symbol."
Did you try doing a 'find' for the string "countNW" in your code, to see where it is used and how it is defined?
Topic archived. No new replies allowed.