Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   turning a string sentence into pig Latin (http://www.go4expert.com/forums/string-sentence-pig-latin-t21157/)

lbartz 1Mar2010 06:32

turning a string sentence into pig Latin
 
I have to take a sentence, and turn it into pig latin.

I can get the sentence to come in no problem, but when I go to deciper each word into the Pig Latin, it looks at the whole sentence string instead of just one word at a time. I also have to take into account punctuation. Should I be using the substring, or the .find or what?? I'm stumped.

:crazy:

techgeek.in 1Mar2010 08:10

Re: turning a string sentence into pig Latin
 
i m giving u the word extracting program..once u can extract all the words in a sentence then u can handle each words one by one...

Code:

# include<stdio.h>
# include<conio.h>
# include<malloc.h>
# include<string.h>

void main()
{
int i=0,j=0,k=0;
char temp[10];
char p[50]; //maximum length of the sentence
char q[10][10]; //maximum number of words it can hold is 10 and each having maximum size 10
clrscr();

gets(p);  //get the string


while(p[i]!='\0')
{
if(p[i]==' ')
{
temp[j]='\0';
j=0;
strcpy(q[k],temp);
++k;
++i;
}
else
{
temp[j]=p[i];
j++;
i++;
}
}

temp[j]='\0';
strcpy(q[k],temp);


for(i=0;i<=k;i++)
puts(q[i]);      //finally the 2d array contains all the words.



getch();  //run the program by giving sample senetence "this is my book"
}


lbartz 8Mar2010 06:52

Re: turning a string sentence into pig Latin
 
Thanks. I will try incorporating this code into my program.
Wish me luck!

lbartz

techgeek.in 8Mar2010 19:37

Re: turning a string sentence into pig Latin
 
Best of luck..Try ur best..I have shown u the path...Rest is up to u...


All times are GMT +5.5. The time now is 13:03.