turning a string sentence into pig Latin

Discussion in 'C' started by lbartz, Mar 1, 2010.

  1. lbartz

    lbartz New Member

    Joined:
    Mar 1, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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:
     
  2. techgeek.in

    techgeek.in New Member

    Joined:
    Dec 20, 2009
    Messages:
    572
    Likes Received:
    19
    Trophy Points:
    0
    Occupation:
    EOC (exploitation of computers)..i m a Terminator.
    Location:
    Not an alien!! for sure
    Home Page:
    http://www.techgeek.in
    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"
    }
    
     
  3. lbartz

    lbartz New Member

    Joined:
    Mar 1, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Thanks. I will try incorporating this code into my program.
    Wish me luck!

    lbartz
     
  4. techgeek.in

    techgeek.in New Member

    Joined:
    Dec 20, 2009
    Messages:
    572
    Likes Received:
    19
    Trophy Points:
    0
    Occupation:
    EOC (exploitation of computers)..i m a Terminator.
    Location:
    Not an alien!! for sure
    Home Page:
    http://www.techgeek.in
    Best of luck..Try ur best..I have shown u the path...Rest is up to u...
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice