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
What does the key combination ctrl+s achieve?
erastovalidia [21]
Control + S I suppose saves files
7 0
4 years ago
Read 2 more answers
The ____ documents a system at the end of the design phase, identifies any changes since the beginning of the project, and inclu
nekit [7.7K]

Answer:

allocated baseline

Explanation:

The allocated baseline documents a system at the end of the design phase, identifies any changes since the beginning of the project, and includes testing and verification of all system requirements and features.

Hope this helps!

5 0
3 years ago
Read 2 more answers
Which is most likely to cause confusion, hinder thinking, and prevent quick access to resources in a study environment? phones c
OverLord2011 [107]
Clutter will cause the most problems when you are trying to study because <span>If you’re unable to get through the material clogging up your </span>neural<span> networks, so the theory goes, you’ll be slower and less efficient in processing information. As a result, you’ll be incapacitated when it comes to short-term memory tasks, and even in longer-range mental exercises when you have to come up with information you should know, such as names of people, that you can no longer find within your disorganized repository of knowledge.

Hope this helps, 

kwrob</span>
3 0
4 years ago
Read 2 more answers
You want to purchase a new hard drive for your workstation and are deciding between an HDD and an SDD. Which of the following is
Ipatiy [6.2K]
HDDs usually wear down faster and give less performance quality than SSD but HDDs are still cheaper. If your aiming for budget , HDD is the right one for you.
3 0
3 years ago
Concept tests in the screening and evaluation stage of the new-product process rely on written descriptions, sketches, or mock-u
pochemuha

Answer:

The answer is "Actual products".

Explanation:

The key purpose of this research is to better analyze the concepts, which is done to establish customer buying expectations and perceptions of the item. The key point is to assess the consumers ' initial response to the product idea.

  • This concept testing is also known as a creation, it is an advantage, which can be conveyed to the user to test their reactions.  
  • In conceptual testing, it is a quality check between the design definition and the actual production of the product.

6 0
4 years ago
Other questions:
  • How can I logout and log in?
    10·1 answer
  • What will you personally do to make your peers aware of the seriousness Of teen crashes?
    9·1 answer
  • Which of the following types of cloud platforms would a webmail service offered to the general public be considered?
    9·1 answer
  • If my computer is next to my book, what preposition would I use?<br> O xià<br> 0 shàng<br> pangbian
    7·1 answer
  • Ruth designs games for mobile operating systems such as iOS and Windows. The demand for games on mobile devices is high. Ruth’s
    8·1 answer
  • During the _______ steps of the information processing cycle, data is manipulated, calculated, or organized to create useful inf
    9·1 answer
  • What is a secondary storage medium that uses magnetic techniques to store and retrieve data on disks or tapes coated with magnet
    6·1 answer
  • To create a new table by using a select statement, you code the ___________________________ clause.
    14·1 answer
  • The Painting Company has determined that for every 112 square feet of wall space:
    5·1 answer
  • Is hp pavilion pc a digital or analog computer
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!