I'm trying to understand strncpy.tokenization and cin.get in this simple program. It should read in a sentence entered by the user, copy it to another variable, tokenize and output the original entry along with the copied version. However it's not printing anything at all! Can anyone help?
Code:
#include <iostream>
using namespace std;
#include <cstring> // prototype for strtok; strtok modifies entry!!
int main()
{
char englishStringEntered[ 99 ]; // limits the string to 99 characters
char englishStringModified[ 99 ]; // storage for tokenized string
char *englishStringModifiedPtr; // creates pointer to englishString
cout << "Enter a Sentence: " << endl;
cin.getline( englishStringEntered, 99, '\n' ); // reads keyboard entry into englishStringEntered
strcpy(englishStringEntered,englishStringModified);
cout << englishStringEntered << endl;
cout << englishStringModified << endl;
englishStringModifiedPtr = strtok( englishStringModified, " " ); // tokenizes entry
// loops over each token until reaching null
while ( englishStringModifiedPtr != NULL ) {
cout << englishStringModifiedPtr << '\n';
englishStringModifiedPtr = strtok( NULL, " " ); // gets next word
} // end while
return 0;
} // end function main