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

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

    Unhappy ^

    Help

  2. #17
    Unregistered
    Guest

    Smile Here's how to stop it

    You have to reorder part of your program to stop it. You put down the following:

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

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

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

    however, you have to move your word comparison with stop before it translates the word into pig latin. Change it to the following.

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

    return 0;

  3. #18
    Registered User
    Join Date
    Oct 2001
    Posts
    38
    Well I did EXACTLY what you said and it works! BUT, it doesnt translate any more Itll run correctlly and when I type something in, it wont turn it into pig latin. But it will wait for me to type stop. Now that works and it stops correctly. But it doenst translate. Heres an exmple of the output:

    ------------------------------------------------------------------------------------
    Welcome to the Pig Latin Translator!

    Please enter your word(s):
    Hello World
    (Translated word should be here but not)
    stop





    ...Press any button to return to turbo C
    ------------------------------------------------------------------------------------

    Here is my entire program below with the changes you told me. Hope you can see what the problem is:


    #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( stricmp( Word, "stop" ) == 0 ) return 0;

    {
    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' */
    }

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

    Unhappy Somebody? Anybody?

    Ive tried moving things, changing things and nothing works

    Help!

  5. #20
    Unregistered
    Guest
    Code:
    while(scanf("%s", Word) == 1) 
    
    if( stricmp( Word, "stop" ) == 0 ) return 0; 
    
    { 
    if(isWord(Word)) PigLatin(Word); 
    return 0; 
    } 
    }
    You've got your brackets all over the place!

    Code:
    while(scanf("%s", Word) == 1)
    
    if (stricmp(Word, "stop") == 0 ) return0;
    ...
    What happens here is, that it'll do that as long as you don't type stop. You see you have to have the { right after the while or else it'll think theres only one function to loop! Also, when you have return 0 inside the {} it'll never go through it more than once because it'll exit because of that return 0; Try this:

    Code:
    while(scanf("%s", Word) == 1) 
    {
    if( stricmp( Word, "stop" ) == 0 ) return 0; 
    
     
    if(isWord(Word)) PigLatin(Word); 
    }
    return 0; 
    }

  6. #21
    Registered User
    Join Date
    Oct 2001
    Posts
    38

    Smile

    Hell yea!!!!! It worked man!!! Thank you a 1000xs! I cannt say how much I appreciate this.

    Now unfortunately its 30 mins till my class and theres 2 things I noticed that need to be done. I have to be able to translate "stop" into pig latin if I use it in a sentence. Thats not the real imorptant thing though. I still have to use "way" for words that begin with a vowel! I know you probably wont see this before than dude, but Im gonna see if the teacher will cut me a little break and let me turn this in late.

    Im thinking to translate a vowel I gotta do something like this:

    while ( Word[i] != 'a' &&
    Word[i] != 'e' &&
    Word[i] != 'i' &&
    Word[i] != 'o' &&
    Word[i] != 'u' &&)

    The thing is I dont know how to put it in. Where it goes. And how to make it say "way". Hell, I dont even know what that "i" [i], is for!!

    *sighhhhhh* This class is a pain

    Thanks alot for your help though man. Its greatly appreciated. Below is my current program. Maybe you can take a look and see what needs to be added or something. Thanks again.

    -------------------------------------------------------------------------------


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

    int EWord(char *str);
    void LWord(char *str);

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

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

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


    if(EWord(Word)) LWord(Word);
    }
    return 0;
    }

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

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

    return !!Cnt;
    }

    void LWord(char *str)
    {
    char head = str[0];

    str++;
    while(*str)
    putchar(*str++);

    printf("%cay ", head);
    }

    ------------------------------------------------------------------------------

    Thanks again

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

    Unhappy

    Damn this dropped down fast...

  8. #23
    Registered User
    Join Date
    Oct 2001
    Posts
    38

    Unhappy

    Getting desperate here...

  9. #24
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    This is the 6th time you've bumped this thread - do it again, and I will delete it - you have been warned.

    As for your code, you've put almost no effort in - apart from changing the names of a couple of functions, it looks the same as it did 3 days ago when you first posted this code.

    > Hell, I dont even know what that "i" [i], is for!!
    Yet you have no problem with this???
    if(!isalpha(*str++)) Cnt = 0;

    > return !!Cnt;
    And as a newbie, you're not likely to stumble upon this by accident either....

    Did you even write this code, because you seem to be struggling with such basic concepts.

    Personally, I think you need to find a different class, this programming doesn't seem to be your thing.
    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.

  10. #25
    Registered User
    Join Date
    Oct 2001
    Posts
    38

    Unhappy

    What? Look dude, my cousin helped me do it. We are both stumped at it. 6 times? Im pretty good at counting and since the last reply I did to unregistered, I bumbed it twice. NO effort into it? Of course it looks the same it did three days ago! I had it practically close to done when I first posted. I was just having some problems. So of course it hasnt changed much!

    I dont see how you became moderator, when you wont let people here get some help. Besides, if you didnt like me bumping because I needed help, why didnt you just help?

    Ohh and I know the main site has tutorials that help out. If you dont want to help, can you at the very least, point me to what I should read or touch up on to do the task of addint in the vowels?
    Last edited by Desperado; 11-16-2001 at 06:02 PM.

  11. #26
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Yeah, 6 posts with no new information
    1. Almost 40 views and no help
    2. 66 views... sigh...
    3. ^ Help
    4. Ive tried moving things, changing things and nothing works Help!
    5. Damn this dropped down fast...
    6. Getting desperate here...

    > NO effort into it?
    Yeah - no effort - nada, squat, zip

    I mean, you posted this over 3 days ago
    > I also just realised I have to trasnlate it differently if it begins with a vowel,
    Oh sure you've sat around prodding at the code, but coding is much more than just making sure all the {} are in the right place, you've got to think about the problem. You recognised that vowels were special, so you should have been thinking about how to recognise vowels in general, and perhaps vowels at the beginning of words in particular.

    So, where is your attempt at trying to recognise vowels then? If you'd at least attempted and posted some kind of 'isVowel' function (like I suggested 11-14-2001 06:47 PM), then perhaps you could have moved the problem forwards.

    > when you wont let people here get some help
    Only when someone like you thinks their problem is more important than everyone elses problem.

    > why didnt you just help?
    Like on the 11th you mean?
    For all I can see, you've ignored what I said.

    > point me to what I should read or touch up on
    Any C beginners book would probably suffice.

    Lets see if you can ignore this....
    Code:
    #include <stdio.h>
    #include <string.h>
    #include <ctype.h>
    
    int isVowel ( char ch ) {
        int res = 0;
        ch = tolower( ch );
        if ( ch == 'a' ||
             ch == 'e' ||
             ch == 'i' ||
             ch == 'o' ||
             ch == 'u' ) res = 1;
        return res;
    }
    
    int beginsConsonant ( char word[] ) {
        return !isVowel( word[0] );
    }
    
    int allConsonant ( char word[] ) {
        int len = strlen( word );
        int i, res = 1;
        for ( i = 0 ; i < len ; i++ ) {
            if ( isVowel(word[i]) ) res = 0;
        }
        return res;
    }
    
    // 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.
    void pigLatin ( char word[] ) {
        if ( beginsConsonant(word) && !allConsonant(word) ) {
            printf( "%s%cay ", &word[1], word[0] );
        } else {
            printf( "%sway ", word );
        }
    }
    
    int main ( ) {
        char line[] = "Do you speak pig latin";
        char *p;
    
        // test cases
        pigLatin( "hello" );// begins consonant
        printf( "\n" );
    
        pigLatin( "are" );  // begins vowel
        printf( "\n" );
    
        pigLatin( "why" );  // all consonant
        printf( "\n" );
    
        // a real sentence
        for ( p = strtok(line," ") ; p ; p=strtok(NULL," " ) ) {
            pigLatin( p );
        }
        printf( "\n" );
    
        return 0;
    }

  12. #27
    Registered User
    Join Date
    Oct 2001
    Posts
    38
    Looks like you assume too much man.

    I didnt ignore anything. I tried stuff out and it didnt work, so I didnt post my current code when I was trying everything.

    But I didnt ignore your code. I used that, put into mine and what I got is below. I moved things, read things, and tried to understand things. Im ofcourse going tohave to ask questions about things in your code because thats the best way to understand things (is that OK?) .

    Current code is below. Im getting 1 error when I try to run it and it says: "Expression Syntax in allConstant"

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

    int EWord(char *str);
    void LWord(char *str);
    int isVowel ( char ch ) {
    int res = 0;
    ch = tolower( ch );
    if ( ch == 'a' ||
    ch == 'e' ||
    ch == 'i' ||
    ch == 'o' ||
    ch == 'u' ) res = 1;
    return res;
    }

    int beginsConsonant ( char word[] ) {
    return !isVowel( word[0] );
    }


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

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

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


    if(EWord(Word)) LWord(Word);
    }
    return 0;
    }

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

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

    return !!Cnt;
    }

    void LWord(char *str)
    {
    char head = str[0];

    str++;
    while(*str)
    putchar(*str++);

    printf("%cay ", head);
    }

    int allConsonant ( char word[] ) {
    int len = strlen( word );
    int i, res = 1;
    for ( i = 0 ; i < len ; i++ ) {
    if ( isVowel(word[i]) ) res = 0;
    }
    return res;
    void pigLatin ( char word[] ) { <~~~~(this is whats highlighted when it shows the error)
    if ( beginsConsonant(word) && !allConsonant(word) ) {
    printf( "%s%cay ", &word[1], word[0] );
    } else {
    printf( "%sway ", word );
    }
    }
    }

    Questions:
    How do I paste my thread to show it as code and everything wont be aligned on the left side?

    Should I get rid of my "printf("%cay ", head);" since the part of your code I inserted already has a function like that?

    Im still reading your code and trying to understand things and everything. But I wanted to post this to show somehting is TRYING to be done.

    Thanks for your help.

  13. #28
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > int allConsonant ( char word[] ) {
    > int len = strlen( word );
    > int i, res = 1;
    > for ( i = 0 ; i < len ; i++ ) {
    > if ( isVowel(word[i]) ) res = 0;
    > }
    > return res;
    You're missing a }

    > How do I paste my thread to show it as code and everything wont be aligned on the left side?
    You read this link
    http://www.cprogramming.com/cboard/m...bbcode#buttons

    Basically, you write
    &#91;code]
    int beginsConsonant ( char word[] ) {
    return !isVowel( word[0] );
    }
    &#91;/code]
    And it ends up looking like this
    Code:
    int beginsConsonant ( char word[] ) {
        return !isVowel( word[0] );
    }
    > Should I get rid of my "printf("%cay ", head);" since the part of your code I inserted already has a function like that?
    Yes - well if you end up calling void pigLatin ( char word[] )

  14. #29
    Registered User
    Join Date
    Oct 2001
    Posts
    38
    Ok man, I added in the } and its still giving me the same error. I guess that wasnt the problem. Im still messing around with it to see what I can do, but I wanted to give a quick reply to keep you updated.

    Ohh and the Error was "Expression Syntax in function allConstant" and the same line was highlighted.
    Last edited by Desperado; 11-20-2001 at 06:03 PM.

  15. #30
    Registered User
    Join Date
    Oct 2001
    Posts
    38
    Ok, I modified some things now and got rid of alot of stuff and modified some other stuff. My current code is below, but the weird thing is Im getting the SAME error! Whats up with that?

    Error: Expression Syntax in function allConstant



    Code:
    #include <stdio.h>
    #include <ctype.h>
    #include <string.h>
    
    int EWord(char *str);
    void LWord(char *str);
    int isVowel ( char ch ) {
        int res = 0;
        ch = tolower( ch );
        if ( ch == 'a' ||
             ch == 'e' ||
             ch == 'i' ||
             ch == 'o' ||
             ch == 'u' ) res = 1;
        return res;
    }
    
    int beginsConsonant ( char word[] ) {
        return !isVowel( word[0] );
    }
    
    
    int main(void)
    {
       char Word[100];
    
       printf("Welcome to the Pig Latin Translator!\n\n");    
       printf("Please enter your word(s):\n\n");
    
    while(scanf("%s", Word) == 1) 
    {
    if( stricmp( Word, "stop" ) == 0 ) return 0; 
    
     
    if(EWord(Word)) LWord(Word); 
    }
    return 0; 
    }
    
    int allConsonant ( char word[] ) {
        int len = strlen( word );
        int i, res = 1;
        for ( i = 0 ; i < len ; i++ ) {
            if ( isVowel(word[i]) ) res = 0;
        
        return res;
        }
    void pigLatin ( char word[] ) {
        if ( beginsConsonant(word) && !allConsonant(word) ) {
            printf( "%s%cay ", &word[1], word[0] );
        } else {
            printf( "%sway ", word );
        }
    }      
    }

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, 10: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, 04: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