Answered step by step
Verified Expert Solution
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
- Create a string of 100 characters in size.
- Create counter variables to count the total number of spaces and total number of characters. Initialize them to 0.
- Prompt the user to enter a string and read it in using the gets function.
- 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'.
- 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started