Hey guys I ned some quick help here with a little program, please.

This is a discussion on Hey guys I ned some quick help here with a little program, please. within the C++ Programming forums, part of the General Programming Boards category; Well I have to do a Turbo C program that translates English sentences into Pig Latin. Accept sentences/lines one at ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    38

    Unhappy Hey guys I ned some quick help here with a little program, please.

    Well I have to do a Turbo C program that translates English sentences into Pig Latin. Accept sentences/lines one at a time until the user types "stop" for the input sentence. I can assume only letters appear that are either upper or lower case, there is no punctuation, and there are less than 80 characters in a sentence (I have to write these assumptions in the user directions). In this Pig Latin, each word is altered by the front consonants (any letters not a,e,i,o,u) being moved to the end and followed by "ay", and words that start with vowels or are all consonants have "way" added to the end. I can assume y is a consonant for this project, unless I want to get fancy, which I dont. An example for this program is: “Do you speak pig latin” would translate to “oDay ouyay eakspay igpay atinlay”.

    This proram seems a little tricky. I have some ideas but I get confused alot and a little upset over it. LOL

    But Id appreciate it if anyone of you Program experts can help out a guy in trouble. Thanks to anyone who helps me. Its greatly appreciated.

  2. #2
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    first order up the string be ensuring that each word only has one space between it and the next... [if you can assume this, then just skip this formatting...]

    second... calculate and reallocate a new buffer that will form the new pig latin translated string... you can do this by counting the words [with consonant initial letters + vowels] and adding 2 times the number... [ay, two characters per...] as well as counting the words [with vowel initial letters or solely consonants] and adding 3 times the number... [way, three characters per...]...

    third... loop through each word, if it's first letter is a consonant... check if has a vowel before the next space... [end of the word]... if so... then you reorder it in the new string based on what type you need [ay, way]...

    that should do it... any ?uestions?
    hasafraggin shizigishin oppashigger...

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    38

    Help!

    Hey, Thanks for the help man. I have this finished right here and it works! But I cant get it do do complete sentences and I cant get it to quit by typing "stop". Heres what I have below and modifications or suggestions would be appreciated.

    #include <stdio.h>
    #include <ctype.h>

    int isWord(char *str);
    void PigLatin(char *str);

    int main(void)
    {
    char Word[100];

    while(scanf("%s", Word) == 1)
    if(isWord(Word)) PigLatin(Word);

    return 0;
    }

    int isWord(char *str)
    {
    int Cnt = 1;

    while(*str)
    if(!isalpha(*str++)) Cnt = 0;

    return !!Cnt; /* If the string contains only alphabetic characters, return 1 otherwise return 0 */
    }

    void PigLatin(char *str)
    {
    char head = str[0]; /* Grab the first character in the word */

    str++; /* Point to the second character */
    while(*str) /* Display the remaining characters */
    putchar(*str++);

    printf("%cay ", head); /* Append the first character plus 'ay' */
    }


    Your help is greatly appreciated.

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    38

    Unhappy

    Almost 40 views and no help

  5. #5
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    for the stop command, just have a check before you pig-latin-ize the sentence such that if the whole string reads 'stop.' [w or w/o the period, your choice...] that you quit... and for sentences, you need to make sure you move to the next word of the sentence... check for the null [or a period] at the very end of the string to know when to stop pig-latin-izing the words...
    hasafraggin shizigishin oppashigger...

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    38
    Cool. I get what your saying man. I just dont know how to do it. lol. I know it sounds dumb, but I cant get it. I was looking in my text book and cant find anything

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    38

    Unhappy 66 views...

    sigh...

  8. #8
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    before you go further in your function... use a call to strcmp () to see if the string reads "stop." if so, then just return... and relax about the replies! unless this is... gulp... homework!!!
    hasafraggin shizigishin oppashigger...

  9. #9
    Registered User
    Join Date
    Oct 2001
    Posts
    38

    Unhappy

    LOL. You hit the nail right on the head man. It is homework. Ive been working my butt off on it and I cant figure alot of it out. The work is due Thursday, so Im trying to rush. Ive been trying things out since Sunday.

    I tried the strcmp () like you said but it didnt work. I think I put it in the wrong spot. I put it here:

    #include <stdio.h>
    #include <ctype.h>

    int isWord(char *str);
    void PigLatin(char *str);
    strcmp (); <~~~~~~~

    int main(void)
    {
    char Word[100];



    Is that where I should put it? If not. where should I slip it in, or am I just missing something else, like another statement or something?

    Thanks for your help man. Its really appreciated.

  10. #10
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    i meant to put it in the function... i find it kinda silly that you put it in no-man's land!

    and it's no problem that it's homework, i can see that you are trying hard at this...
    hasafraggin shizigishin oppashigger...

  11. #11
    Registered User
    Join Date
    Oct 2001
    Posts
    38

    Unhappy

    Well dude I guess Im showing my stupidity here but I cant get nothing to work. I dont know if its cause Im just getting really frusturated and Im not thinking correctly or what, but Im totally lost. Your gonna have to explain in etreme Layman's Terms.

    Im guessing I gotta put something like this in there:

    while != "stop"
    gets (sentence);

    *or*

    while sentece not = "stop"
    while word not NULL

    I also just realised I have to trasnlate it differently if it begins with a vowel, I have to print the word + "way". But I dont know how to do that!

    I am sooooooooooo desperate here, Ill even send cash to anyone who can help me get this crap done.

  12. #12
    Unregistered
    Guest
    Code:
    while(scanf("%s", Word) == 1) 
    
    if (strcmp(Word, "Stop") == 0) return 0;
    
    if(isWord(Word)) PigLatin(Word);
    I can't remember if strcmp(); returns 0 when the two strings equal, but I think it was like that. strcmp(); takes two STRings and CoMPares them =)

  13. #13
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    > and words that start with vowels or are all consonants have "way" added to the end
    Well you've got part of the problem solved at least, with the adding of
    printf("%cay ", head); /* Append the first character plus 'ay' */

    However, you don't solve the other two cases (start with vowel, or all consonants)

    You have used isalpha elsewhere, but what you also need is an 'isVowel' function. There isn't a standard one, so you'll need to write your own.

    Once you know which type of word you have, you can append the right suffix ("ay" or "way")
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  14. #14
    Unregistered
    Guest

    Stop


    I tried the strcmp () like you said but it didnt work. I think I put it in the wrong spot. I put it here:

    #include <stdio.h>
    #include <ctype.h>

    int isWord(char *str);
    void PigLatin(char *str);
    strcmp (); <~~~~~~~

    int main(void)
    {
    char Word[100];
    try this

    int main(void)
    {
    char Word[100];

    while(scanf("%s", Word) == 1)
    {
    if( stricmp( Word, "stop" ) == 0 )
    return 0;

    if(isWord(Word)) PigLatin(Word);

    return 0;
    }


    That checks to see if the text in Word is stop. Its not case sensitive. With strcmp/stricmp if the 2 buffers are equal it returns a zero. This way, if stop is in Word the program just returns.

  15. #15
    Registered User
    Join Date
    Oct 2001
    Posts
    38

    Unhappy

    OK, heres my current program below and it totally works!

    BUT, and this is a big BUT!

    I did your suggestion Unregistered, but its NOT stopping! BUT, I am now able to do full sentences for some odd reason. All I did was add what you said and if you look at my program below its in there in an OK spot. Im getting no errors and its running.

    But the problem still remains that it wont stop. I also have to add in the "way" for vowels.

    So this program is ALMOST complete. But I need a little more help. Thanks EVERYONE for your suggestions. And I couldnt have gotten this far without your help. But now I need just a little more. Thanks and ALL help is appreciated.

    *My current, running program*

    #include <stdio.h>
    #include <ctype.h>

    int isWord(char *str);
    void PigLatin(char *str);

    int main(void)
    {
    char Word[100];

    printf("Welcome to the Pig Latin Translator!\n\n");
    printf("Please enter your word(s):\n");

    while(scanf("%s", Word) == 1)

    if(isWord(Word)) PigLatin(Word);

    return 0;
    {
    if( stricmp( Word, "stop" ) == 0 )
    return 0;
    }
    }

    int isWord(char *str)
    {
    int Cnt = 1;

    while(*str)
    if(!isalpha(*str++)) Cnt = 0;

    return !!Cnt; /* If the string contains only alphabetic characters, return 1 otherwise return 0 */
    }

    void PigLatin(char *str)
    {
    char head = str[0]; /* Grab the first character in the word */

    str++; /* Point to the second character */
    while(*str) /* Display the remaining characters */
    putchar(*str++);

    printf("%cay ", head); /* Append the first character plus 'ay' */
    }
    Last edited by Desperado; 11-14-2001 at 04:54 PM.

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hey Guys! I Need Some Help Here!
    By Ruski in forum C++ Programming
    Replies: 6
    Last Post: 06-27-2002, 02:13 AM
  2. Hey i got a quick Question
    By cis in forum C Programming
    Replies: 1
    Last Post: 03-15-2002, 09:12 PM
  3. Hey guys, wanna see a picture of me?
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 53
    Last Post: 11-29-2001, 03:56 PM
  4. Hey Guys
    By D4050 in forum C Programming
    Replies: 0
    Last Post: 10-01-2001, 06:20 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21