I am trying to create a program that will count and display the number of vowels, consonants, spaces and full-stops within a 50 character limit. There is one error that the compiler keeps bringing up and when i try to fix it by changing the text it creates more errors - I am in a bit of a pickle.
The error reads; Text Analyzer Assignment.ccp(14.5):Statement missing ;

#include <stdio.h>
void main(void)
char text[50], *ptr;
int spaces=0, vowels=0, consonants=0, other=0;

printf("Enter text: ");

for (ptr=text; *ptr; ptr++)

if (*ptr == ' ') spaces++

//the error is in the line below//
[B]else if (*ptr == 'a' || *ptr == 'e' || *ptr == 'i' || *ptr == 'o' || *ptr == 'u' || *ptr == 'A' || *ptr == 'E' || *ptr == 'I' || *ptr == 'O' || *ptr == 'U') vowels++;[/B]

else if ((*ptr > 'a' && *ptr <= 'z') || (*ptr > 'A' && *ptr <= 'Z')) consonants++;
else other++;

printf("There were:\r\n");
printf(" %d vowel%s\r\n", vowels, vowels == 1 ? "" : "s");
printf(" %d consonant%s\r\n", consonants, consonants == 1 ? "" : "s");
printf(" %d space%s\r\n", spaces, spaces == 1 ? "" : "s");
printf(" %d other character%s\r\n", other, other == 1 ? "" : "s");

Any good advice would be very helpful: I know that this is basic stuff but it will help me out greatly.

Recommended Answers

All 11 Replies

hey, you are missing a semi-colon in

if (*ptr == ' ') spaces++;

Hope it will work now.

And while posting the code in the form please use the code tags so that it becomes more readable.

will do thanks

Ahamed101 you are a life saver - It's amazing how you can get distracted when the complier tells you to looks somewhere else - it is possible to miss the obvious - Thank you very much!!! :-)

use int main() because void main() is bad

just remember to return 0; at the end of your code.

That's ace - thanks I have just sorted that after much searching on the web and in books. Could you tell me how could I total up the number of characters used? The program works fine now with everyones help just need this one last peice of help...as always I will search myself as well.

Thanks in advance for all your help

just add up the ints I suppose printf(" %d Total character%s\r\n", (vowels + consonants + spaces + other), (vowels + consonants + spaces + other) == 1 ? "" : "s"); the brackets are in there for clarity only, the compiler should use operator order precedence to figure out what is meant but sometimes the wetware can be fooled :)

#include <stdio.h>
#include <time.h>
#include <ctype.h>
#include <stdlib.h>
int main()

/*First I declare my integers*/

char text[50], *ptr;
int spaces=0, vowels=0, consonants=0, other=0, fullstops=0;

/*Then I tell the program to display a welcome message*/
printf("... Welcome to Paul Hill's Text Analyser ... \n\n... Please enter your desired text to be analysed \n\n... Here: ");

for (ptr=text; *ptr; ptr++)

/*I then specify what characters belong to the integers...basically what the program should look for to get it's result*/
if (*ptr == ' ') spaces++;
else if (*ptr == 'a' || *ptr == 'e' || *ptr == 'i' || *ptr == 'o' || *ptr == 'u' || *ptr == 'A' || *ptr == 'E' || *ptr == 'I' || *ptr == 'O' || *ptr == 'U') vowels++;
else if ((*ptr > 'a' && *ptr <= 'z') || (*ptr > 'A' && *ptr <= 'Z')) consonants++;
else if (*ptr == '.') fullstops++;
else other++;

/*I then specify what text appears when the program offers it's results*/
printf("\n... Thank you. Please find your results below:\r\n");
printf("\n\n %d Vowel%s\r\n", vowels, vowels == 1 ? "" : "s");
printf(" %d Consonant%s\r\n", consonants, consonants == 1 ? "" : "s");
printf(" %d Space%s\r\n", spaces, spaces == 1 ? "" : "s");
printf(" %d Other character%s\r\n", other, other == 1 ? "" : "s");
printf(" %d Full-stop%s\r\n", fullstops, fullstops == 1 ? "" : "s");
printf(" %d Total character%s\r\n", (vowels + consonants + spaces + other + fullstops), (vowels + consonants + spaces + other + fullstops) == 1 ? "" : "s");
printf("\n\n\... Would you care to try again? ... \n\n... Please enter either Y/y to continue or N/n to quit\r\n\n... Here:");

return 0;

I have been struggling for over a day now with trying to make this program loop successfully in regards to the question; Would you care to try again? ... Please enter either Y/y to continue or N/n to quit.

I am simply not sure what I need to do to get the right response from the program - any help would be greatly appreciated.

I am not sure if i need to declare the Y/y N/n before hand or what exactly the right thing to put is - I have tried messing around with do while loops and while loops but in this situation I am not sure what is the correct way to proceed - I get little tuition at college. :-) Help?

wrap your logic in a while loop and add a flag.

int doagainFlag = 1;
char doagain;

while (doagainFlag)
  printf ("do you wish to try again?");
  doagain = getchar(); 
  if ((doagain == 'n') || (doagain == 'N'))
    doagainFlag = 0;

this should do the trick, it's off the cuff so there's probably typos and it won't compile by itself or even have the correct functions :) but it should give you an idea of how to tackle it.

Thank you very much - it was a great help. It does loop now but it wont allow me to input new sentences after i say Y/y it just loops and makes some figures up. Thank you very much though - Thank you for taking the time to help. :-)

you'll have to put all the logic including the input portion inside the while loop and don't forget to reset the integers (unless you want to keep running totals of course).

Be a part of the DaniWeb community

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