1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Shalnov [3]
3 years ago
13

Write a function that accepts a pointer to a C-string as an argument and returns the number of words contained in the string. Fo

r instance, if the string argument is 'Four score and seven years ago,' the function should return the number 6. Demonstrate the function in a program that asks the user to input a string and then passes it to the function. The number of words in the string should be displayed on the screen.
Computers and Technology
1 answer:
Anon25 [30]3 years ago
4 0

Answer:

To preserve the original format of the answer, I've added it as an attachment

Explanation:

This line defines the function

int countWords(const char ptr){

   

This line initializes number of words to 0

   int words = 0;

The following iteration is repeated until the last character in the argument is reached

   while(*(ptr) != \0){

This checks if current character is blank

       if(*ptr==  ){

If yes, then it increments number of words by 1

        words++;

 }

This moves the pointer to the next character

       ptr++;

   }

This returns the number of words in the argument

   return words+1;

}

The main begins here

int main() {

This declares user input as a character of 200 length

   char userinput[200];

This prompts user for input

   cout << Enter a string: (200 max): ;

This gets user input

cin.getline(userinput, 200);

This passes the c-string to the function and also prints the number of words

cout << There are  << countWords(userinput)<< words;

Download cpp
You might be interested in
Please help will give brainliest
ludmilkaskok [199]

Answer:

waterfall- google search

Explanation:

5 0
3 years ago
1.
Alecsey [184]
I think
The start and end shape
7 0
3 years ago
Which command can be used to connect to a remote windows share called data on the server called fileserver?
DiKsa [7]

c. c.) smbclient //fileserver/data

7 0
3 years ago
What is the answer ??​
Blizzard [7]

Answer:

D all of the above

B operating system

7 0
3 years ago
Read 2 more answers
<img src="https://tex.z-dn.net/?f=%28a%20%2B%20b%29%20%20%7B2%7D" id="TexFormula1" title="(a + b) {2}" alt="(a + b) {2}" align
MariettaO [177]

Answer:

ab2

Explanation:

3 0
3 years ago
Other questions:
  • What are options in the Advanced tab in the Share Workbook dialog box? Check all that apply
    14·2 answers
  • Which of the following is a disadvantage of using open source software?
    14·1 answer
  • Which remote access configuration option should you choose if you want mobile users to be able to make a secure connection to th
    9·2 answers
  • What technology habit you practice every day that you need to stop to be more successful?
    13·1 answer
  • Integrity is keeping data consistent and free of errors or anomaliea<br> True or false
    7·1 answer
  • What does the video say is the number-one requirement for Tour Guides?
    12·2 answers
  • 1 #include 2 3 int max2(int x, int y) { 4 int result = y; 5 if (x &gt; y) { 6 result = x; 7 } 8 return result; 9 } 10 11 int max
    12·1 answer
  • Select the best answer from the drop-down menu. Sometimes people feel threatened by new ideas and different ways of doing things
    5·1 answer
  • In your own view, how can social media be used in teaching and learning in higher education?
    10·1 answer
  • What should the Dhruv consider when connecting to the Internet in a public place? Select all that apply.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!