Answer to Question #20178 in C++ for apoorva

Question #20178
Write a program to count number of spaces in a string.
1
Expert's answer
2012-12-07T04:08:47-0500
#include <iostream>
using namespace std;

#define n 100

void main(){
char str[n];
int i;
for (i=0; i<n; i++) str[i] = NULL;
cout<<"Enter a string: ";
gets(str);
int c=0; i=0;
while (str[i]!=NULL){
if ((int)str[i] == 32) c++;
i++;
}

cout<<"There are "<<c<<" spaces in the string.\n";
}

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