Hi all,

I'm pretty new to programming and am attempting to build a text formatting program to help further my knowledge.

Its still in the early stages, but i've come across a problem. Here is a snippet of my program. The program will count the number of spaces in a given string.

I am getting errors related to the if statement. Can someone please point out what I am doing wrong?

Thanks.


Code:
#include <iostream>

using namespace std;

main()
{
    char str[20] = {"This is my string"};
    char *ptr;
    ptr = str; //point to beginning of array
    int counter=0;
    
    while (*ptr != '\0')
    {
        if (*ptr == " ") 
        {
            ++counter;
        }
        *ptr++;
    }
    
    cout << "There are " << counter << " spaces\n";

    system("PAUSE");
    return 0;
}