76 805
Assignments Done
Successfully Done
In June 2019

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: ";
int c=0; i=0;
while (str[i]!=NULL){
if ((int)str[i] == 32) c++;

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!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions