67 152
Assignments Done
99,4%
Successfully Done
In November 2018

Answer to Question #15220 in C++ for chinatsu

Question #15220
what does the line below do?

!wordFlag

int words(const char sentence[ ]){
int numberOfWords=0;
int wordFlag=0;
char* pointer=sentence;
while ((*pointer)!=NULL)
{
if(((*pointer)!=' ')&&((*pointer)!='\n')&&((*pointer)!='\t')&&(!wordFlag))

{
numberOfWords++;
wordFlag=1;
}
if(!(((*pointer)!=' ')&&((*pointer)!='\n')&&((*pointer)!='\t')))
{
wordFlag=0;
}
pointer++;
}
return numberOfWords;
}
Expert's answer
#include <iostream>
#include <conio.h>
using namespace std;

int words(char sentence[]){
int numberOfWords=0;
int wordFlag=0;
char* pointer=sentence;
while ((*pointer)!=NULL) {
if(((*pointer)!=' ')&&((*pointer)!='
')&&((*pointer)!=' ')&&(!wordFlag)) {
numberOfWords++;wordFlag=1; }
if(!(((*pointer)!=' ')&&((*pointer)!='
')&&((*pointer)!=' '))) {
wordFlag=0; }
pointer++; }
return numberOfWords;
}

int main ()
{
char sentence[] = "abcdefd";
cout << words(sentence);
system("pause");
return 0;
}

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