Here is the source code I came up with:

#include <stdio.h>
#define SPACE ' '
int main(void)
{
    char c, prev;
    int space, newline;
    long other;

    space = 0;
    newline = 0;
    other = 0L;

    printf("Enter text to be analyzed (# to terminate):\n");

    __fpurge(stdin);   /* clears buffer */

    while((c = getchar()) != '#')
    {
        if(c == (SPACE || '\n'))
        {
                if(c == SPACE)
                                space++;
                if(c == '\n')
                                newline++;
        }

    else
        other++;

    }

    printf("There are %d spaces, %d newline characters, and %d other characters.\n",
        space, newline, other);

    getchar();
    getchar();
    return 0;
}

Most everything works fine, except when I type Brent [ENTER] #, I get 6 other characters instead of just 5, one for each letter of Brent. I believe it might have something to do with the [ENTER] but I am not sure. Anyone have any ideas?

Hi
I ran your program and i inputted the following text for your program.

Enter text to be analyzed (# to terminate):
brent#
There are 0 spaces, 0 newline characters, and 5 other characters.

And as you can see i am getting 5 other characters. The only change i made to your program is ..

printf("There are %d spaces, %d newline characters, and %ld other characters.\n",space, newline, other);

hope this helps

Hmm i understood your problem my input wasn't correct but yeh you should change the %d to %ld, the compiler i used was giving me errors because of that :). If i can find a solution i will let you know

Most everything works fine, except when I type Brent [ENTER] #, I get 6 other characters instead of just 5, one for each letter of Brent. I believe it might have something to do with the [ENTER] but I am not sure. Anyone have any ideas?

That's exactly what your 'problem' is.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.