/* I need this code to correctly out put a malformed sentence removing spaces and is terminated by a period.
Example: this is a TEST .
Should be : This is a test. */
#include <iostream>
#include <cstring>
#include <cctype>
usingnamespace std;
void takeLine(char sentence[]);
int main()
{
char sentence[100];
cout << "Enter a sentence. ";
cin.getline(sentence, 99);
cout << endl;
takeLine(sentence);
cin.get(); // is standard, "system ("PAUSE")" wouldnt work on a operating system other than windows.. js
return 0;
}
void takeLine(char sentence[])
{
int i = 0;
sentence[i] = toupper(sentence[i]); // converts first letter to upper case
i++;
for (i; i < strlen(sentence); i++) // converts all the letters after the first one to lower case
sentence[i] = tolower(sentence[i]);
cout << sentence << endl;
}
ill try to figure out how to fix the space after the period problem and let you know if i figure it out, im still a noob q:
void takeLine(char sentence[])
{
int i = 0;
char *p;
sentence[i] = toupper(sentence[i]); // converts first letter to upper case
i++;
for (i; i < strlen(sentence); i++) // converts all the letters after the first one to lower case
sentence[i] = tolower(sentence[i]);
p = strtok(sentence, ("' .'")); // sloppy but does the trick
while (p != NULL ){
cout << p;
p = strtok(NULL, ("' .'"));
if (p == NULL)
cout << ".";
else
cout << " ";
}
}