A: You can't define a function inside another function.
1: Where did I do this?
A: You didn't, because you can't.
Look at line 45, ¿what are you trying to do there?
It looks that you wanted to provide the body of the function. To do that it should be
1 2 3 4 5 6 7 8
|
int main(){
/* program */
}
//outside main
int char_type(char){ //defining the function
//...
}
|
Your code is obfuscated. It is hard to follow, you've got a lot of global variables, you assign them values but never use them, have local variables with the same name,
embed error code, handling the same error multiple times (the opening of the file), embed debug code,
repeated code, bad indentation, etc.
So based in your description is the suggested code. It shouldn't bother that I've used
std::cin instead of a file, they are both streams and the behaviour should be the same.
Besides you could redirect the standard input to a file
By instance
$ ./program.bin < input.txt
, instead of reading from the keyboard it will read from the file
Oh, didn't realize that there was a typo
1 2 3
|
while(std::cin>>ch) //while you can read a character
if( isdigit(ch) or ispunct(ch) ) //if the character is "valid"
std::cout << ch; //output it
|