Small string program help please
Hi, I'm trying Chapter 5, programming question 35 in the Dietel book and I come accross these 2 errors:
It's supposed to be a PigLatin word program, and I'm trying to take in a whole sentence, break it up into words, take the first letter and place that at the end of the word, then add 'ay' to it.
I'm also learning how to pass data to functions without needing to pass by value or reference when that uses up time and memory to make another copy of the data for pass by value. So, I'm trying to pass through pointer references.
Code:
//Chapter 5.35
#include <iostream>
#include <cstring>
using namespace std;
//Used to break the input string into individual word tokens.
//After that, it will call Print_Latinword to change to tolken word into PigLatin and cout it.
void Tolkenize (char *input);
//ACCEPTS: The tokenized word from function Tolkenize.
//DOES: It will take the 1st letter from the word.
// Shifts the rest of the string down an index.
// Places the first letter at the end of the string word, and then adds 'ay' to it.
// Cout's the new PigLatin word.
//RETURNS: Nothing.
void Print_Latinword (char *S1);
int main()
{
char input[81];
cout << "Enter a short phrase of words."
<< "\nThis program will break that phrase into seperate words and convert them to PigLatin."
<< endl;
cin.getline(input,80);
Tolkenize(input);
return 0;
}
void Tolkenize (char *input)
{
char token[30];
do
{
for (int i=0; i<20; i++)
{
token[i] = '\0'; //Resets the token string to NULL
}
token = strtok(input, " "); //ERROR
cout << "\nDEBUG: This is the token: " << token << endl;
Print_Latinword(token);
} while (token != '\0');
return;
}
void Print_Latinword (char *S1)
{
char first_letter = *S1;
for(; S1 != '\0'; S1++)
{
*S1 = *(S1+1); //Moves the rest of the letters in the string down an index.
}
strcat(S1, first_letter); //ERROR
strcat(S1, "ay");
cout << "\n\nThe new PigLatin word is: " << S1 << endl;
return;
}
For the 2 errors, Visual C++ 6.0 gives me this:
1. '=' cannot convert from char* to char. This conversion requires a reinterpret_cast.
2. 'strcat': cannot convert parameter 2 from 'char' to 'const char *'
Thanks for the help. :)