I writing a pig latin generator. Some times it prints out the english phrase fine, other times it doesn't
For instance "i want to have fun prints out
iay antway tnoway avehay eunfay
The buffer doesn't empty out after each word.
Help !
Here is my code:
#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;
int len=0,i;
char postfix[3]="ay";
char tmp[2]="\0";
char word[10]="\0";
void printLatinWord(char *token)
{
len=strlen(token);
//get first char
strncpy(tmp,token,1);
///copy backwards to get string
strrev(token);
strncpy(word,token,len-1);
// reverse it back no we have the string
strrev(word);
//add first and postfix;
cout<<word<tmp<<postfix<" ";
}
int main()
{
char *token;
char sentance[50];
cout<<"Enter in English sentance to be translated->";
cin.getline(sentance,50);
token=strtok(sentance," ");
while (token != NULL )
{
printLatinWord(token);
token=strtok(NULL, " ");
}
system("Pause");
}
#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;
int len=0,i;
char postfix[3]="ay";
char tmp[2]="\0";
char word[10]="\0";
void printLatinWord(char *token)
{
len=strlen(token);
//get first char
strncpy(tmp,token,1);
///copy backwards to get string
strrev(token);
strncpy(word,token,len-1);
// reverse it back no we have the string
strrev(word);
//add first and postfix;
cout<<word<tmp<<postfix<" ";
}
int main()
{
char *token;
char sentance[50];
cout<<"Enter in English sentance to be translated->";
cin.getline(sentance,50);
token=strtok(sentance," ");
while (token != NULL )
{
printLatinWord(token);
token=strtok(NULL, " ");
}
system("Pause");
}
To copy to clipboard, switch view to plain text mode
Bookmarks