Hello all again, back with another noob project and my teacher once again acts like it is a test and says "read the book" if you have questions. He might as well not be a teacher.
Well, my lab is as follows:
"Using pointers create a function called stripWhite that will strip all of the white spaces from an array of characters. Your function should return the number of white spaces that you deleted.
White spaces can be a number of characters, but in our case we are only concerned with the blank space character (space bar) which is the character Decimal 32 or Hex 20.
Your prototype should be something like:
int stripWhite(char *str); << This should be used for the function that will strip the spaces.
Your output should look something like the following:
Enter a sentence and I will strip out all spaces:
The quick brown fox jumped over the lazy old dog
Your sentence without spaces is:
Note: Passing an array does not count as using pointers. So, if your only use of pointers is this:
int stripWhite(char *str)
Below is my logic behind the problem, I know it is not in code, but it is simply the logic, the "way to solve" the issue. I am just learning so I need to take this step by step and hopefully you guys will be there to help me out!
One main concern that I have is the last note... It states that using pointers just to point to the array in the header of the function is NOT using pointers to pass the array????? I have no idea what this means and once again, he does not answer emails so please help me out!
As you can see from my logic below, I am very amateur at this, also, I have no idea how to re-print the sentence without spaces. I have a good idea of how to count the no. of spaces, but not how to re-print the sentence without spaces.
I can only use really basic libs like iostream, ctime, and cmath.
I can only use cin and cout.
Thanks in advance for reading, hopefully I can get some answers to my preliminary questions. I will go ahead and start writing code and post up what I come up with soon! Thanks again.
Declare the character array.
Program asks for sentence.
The input breaks the sentence into words and spaces, putting each word or space into it's own array location.
Call stripWhite function (not sure what to use for arguments since it will be using pointers)
Retrieve the return value from the stripWhite function.
Print out the number of spaces.
Print out the sentence without the spaces
int stripWhite(char *array)
Use a for loop to go through each block of the array and using an if statement to add to a counting integer to count the amount of times the array section equals a white space.
Return the no. of spaces.