2012-12-06T07:58:18-05:00
Write a program to count the number of words in a string as well as the number of characters other than a space.
1
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 !
Learn more about our help with Assignments:
C++
Comments