I just don't get why this code:
Code:
void Tolkenize (char *input)
char *token_ptr;
token_ptr = strtok(input, " "); //Gets the first word
cout << "\nDEBUG: This is the token: " << token_ptr << endl;
while(token_ptr != NULL)
{
cout << "\nDEBUG: This is the token: " << token_ptr << endl;
Print_Latinword(token_ptr);
token_ptr = strtok(NULL, " ");
}
return;
}
Doesn't seem to work right. It works for tokenizing This, but when it tokenizes that, it only gets "t" and nothing else. Why is that?
Also, that phone number program tokenizes right now, but it doesn't send the values through the pointers back into main for some reason, yet I followed the C++'s book's examples when dealing with this.
Code:
#include <iostream>
#include <cstring>
using namespace std;
void Get_Data (char input[]);
void Tokenize (char input[], char *areacode, char *begin, char *end);
void Concatanate (char *areacode, char *begin, char *end);
int main()
{
const int SIZE = 15;
char input[SIZE];
char areacode[6];
char begin[4];
char end[5];
Get_Data(input);
Tokenize(input, areacode, begin, end);
// cout << "\nDebug: areacode in main: " << areacode[0] << endl;
Concatanate(areacode, begin, end);
return 0;
}
void Get_Data (char input[])
{
cout << "Enter a phone number in the format: (area code) ###-####" << endl;
cin.getline(input, 15);
return;
}
void Tokenize (char input[], char *areacode, char *begin, char *end)
{
areacode = strtok(input, " ");
cout << "\nDEBUG: areacode: " << areacode << endl;
begin = strtok(NULL, "-");
cout << "\nDEBUG: begin: " << begin << endl;
end = strtok(NULL, "\0");
cout << "\nDEBUG: end: " << end << endl;
return;
}
void Concatanate (char *areacode, char *begin, char *end)
{
char phone_number[9] = {'\0'};
strcat(phone_number, begin);
strcat(phone_number, "-");
strcat(phone_number, end);
cout << "\n\nThis is the phone number again:" << endl;
cout << areacode << " " << phone_number << endl;
return;
}