63 152
Assignments Done
99,1%
Successfully Done
In July 2018

Answer to Question #20178 in C++ for apoorva

Question #20178
Write a program to count number of spaces in a string.
Expert's answer
#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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions