C++ Count Spaces by Shane Zentz

/*************************************************************
* Shane Zentz *
* 4-10-07 *
* *
* --> A simple program to count the number of spaces in a *
* user entered string. *
*************************************************************/
#include
#include
#include
using namespace std;

int count_space(char s[], int n);

int main()
{
const int n = 200;
char line[n];
cout << "Enter a line of text: " ;
cin.getline(line, n);
cout << "Your text contains " << count_space(line, 0)
<< " spaces. " << endl;
return EXIT_SUCCESS;
}

// Recursive function to count spaces in an
// array of characters.....................
int count_space(char s[], int n)
{
if (s[n] == '\0')
return 0;

// return 0 if array is empty.
else if (isspace(s[n]))
return 1 + count_space(s, n+1);

else
return count_space(s, n+1);
}