Answer to Question #20172 in C++ for apoorva

Question #20172
Write a program to count the number of words in a string as well as the number of characters other than a space.
1
Expert's answer
2012-12-06T11:50:29-0500
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <iostream.h>
int main(void)
{
char s[255];
cout<<"Enter the string: ";
gets(s);
unsigned int a,i;
a=0;
for (i=0;i<strlen(s)-1;i++)
& if ((s[i]==' ') && (s[i+1]!=' '))
& a=a+1;
if (s[0]!=' ')
a=a+1;
cout<<"number of words: "<<a<<endl;
a=0;
for (i=0;i<strlen(s)-1;i++){
if (s[i+1]!=' ')
& a=a+1;
}



cout<<"The number of characters other than a space : "<<a<<endl;



system ("PAUSE");

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS