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;
}
1
Expert's answer
2012-11-08T08:15:50-0500
#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 the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS