Hello, I'm sorry to bug everyone again, but I've just been so overloaded with classwork and tests, I need a bit of help with the final C++ assignment. (Seriously, taking 20 units is not fun! I have 3 midterms this week, a speech and a research paper due, I don't have as much time as I need to do everything!) For this, the professor wants us to do the following "Using pointers write 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."
He said that we could use strings, although he has not said much at all about strings, so I don't have a good knowledge of them. (Nor has he said much about pointers... He really doesn't explain things well.) Thus I am using character arrays. Any help would be greatly appreciated, I know I must be a bother, but I can't thank you enough for all the help that you guys have given!
He said that we could use strings, although he has not said much at all about strings, so I don't have a good knowledge of them. (Nor has he said much about pointers... He really doesn't explain things well.) Thus I am using character arrays. Any help would be greatly appreciated, I know I must be a bother, but I can't thank you enough for all the help that you guys have given!
Code:
#include <iostream>
using namespace std;
void print(char sentence2[],int size);//function to print sentence when done
void stripWhite(char point[],char sentence2[],int size);//uses pointers to strip sentence of spaces
int main ()
{//main
char sentence1[1000];//first array to obtain sentence
int size;//integer to decide how big new array should be
cout << "Please enter a sentence and I will strip it of all spaces." << endl;
cin >> sentence1;//input for first array
for(int i=0;i<1000;i++)//for loop to find out size of array
{//for
if(sentence1[i] >= 'a' && sentence1[i] <= 'z' || sentence1[i] == ' ' || sentence1[i] == ',' || sentence1[i] == '.')
{//if
size++;
}//if
}//for
char sentence2[size];//new array with exact size it should be
for(int y;y<size;y++)//for loop to copy contents of first array to second
{//for
sentence2[y]=sentence1[y];
}//for
char point;//soon to be pointer
for(int y;y<size;y++)//for loop to get point to become a pointer to second array
{//for
point[y]=&sentence2[y];
}//for
cout << endl;
stripWhite(sentence2,point,size);
return 0;
}//main
void print(char sentence2[],int size)//print function
{//void print
for(int z;z<size;z++)
{//for
cout << sentence2[z];
}//for
}//void
char stripWhite(char point[],char sentence2[],int size)//function to strip sentence of spaces
{//char stripWhite
for(int y;y<size;y++)//for loop to only set non space characters to second array
{//for
if(point[y]!=' ')//if to decide if it is a space or not
{//if
sentence2[y]=*point[y];
}//if
}//for
print(sentence2,size);//function call to print finished sentence
}//char