Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this assignment we are going to find and count the spaces within a string. Your code will go through the string and every time

For this assignment we are going to find and count the spaces within a string. Your code will go through the string and every time a space character is encountered it will output the index that it saw it. At the end your code will output the total number of spaces seen and the total number of characters in the string.

NOTE: The total number of character is NOT the same as the size of the string. This is the number of characters up to, but not including the null character \0.

Steps

  1. Create a string of 100 characters in size.
  2. Create counter variables to count the total number of spaces and total number of characters. Initialize them to 0.
  3. Prompt the user to enter a string and read it in using the gets function.
  4. Create a loop to go from index 0 to the point that a '\0' character is seen.
    • If the character is a space output which index you are at.
    • If the character is space add one to the total spaces.
    • Add one to the total number of characters so long as the character is not '\0'.
  5. Output the total number of spaces and total number of characters.

PLEASE code in C only! Thank you!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

1285427106, 978-1285427102

More Books

Students also viewed these Databases questions

Question

600 lb 20 0.5 ft 30 30 5 ft

Answered: 1 week ago