Thread: real help needed

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    134

    pig latin program done-need help urgently

    i got my act together and wrote the pig latin program, i just think i was overwhelmed when I first saw the description. Well the issue now is that I dont care about how it looks, but the output is not what the assignment requires, what am I doing wrong
    I am attaching a text file with the desired output. thanks alot and once again sorry!!!!

    Code:
    
    
    #include <string.h>
    #include <stdio.h>
    #include <ctype.h>
    #include <stdlib.h>
    
    char ch;                                                            /**/
    int v, x, y, z;                                                     /**/
    char temp[25];                                                      /**/
                                                                        /**/
                                                                        /**/
    void end ( void );                                                  /**/
    void PigLatin(char *str);                                           /**/
    void clear_temp ( void );                                           /**/
                                                                        /**/
    int main(void)
    {                                                                   /**/
                                                                        /**/
                                                                        /**/
                                                                        /**/
                                                                        /**/
                                                                        /**/
                                                                        /**/
                                                                        /**/
    
            do {
    
               char phrase[1000];                                       /**/
    
               
               printf( "Enter your dialog to be converted.");           /**/
               printf( "\n" );                                          /**/
               fflush ( stdin );                                        /**/
               gets( phrase );                                          /**/
                                                                        /**/
               y = 0;                                                   /**/
               x = strlen ( phrase );                                   /**/
               z = 0;                                                   /**/
                                                                        /**/
                                                                        /**/
               printf("Your phrase is: %s", phrase );                   /**/
               printf("\n\n");                                          /**/
                                                                        /**/
               printf("In Pig Latin that's: ");                         /**/
               do {                                                     /**/
                   if ( isspace (phrase[y]) == 0 ){                     /**/
    				   temp[z] = phrase[y];                             /**/
                     z = z + 1;                                         /**/
                   }                                                    /**/
                   else PigLatin ( temp );                              /**/
                   y = y + 1;                                           /**/
                                                                        /**/
               } while ( y <= x );                                      /**/
               PigLatin ( temp );                                       /**/
                                                                        /**/
    
               if ( phrase[x-1] == '!' || phrase[x-1] == '.' || phrase [x-1] == '?' ) {
                printf ("\b%c", phrase [x-1] );
               }
    
               
               printf ( "\n\n\n" );
               printf( "Would you like to do another one?");            /**/
               printf ("\n" );
               
               do {                                                     /**/
                        printf( "Enter ""y"" or "" n"".");              /**/
                        printf ( "\n" );                                /**/
                        fflush ( stdin );                               /**/
                        scanf( "%c", &ch );                             /**/
                        ch = tolower ( ch );                            /**/
                                                                        /**/
               } while ( ch != 'n' && ch != 'y');                       /**/
    
               
    
            } while (ch != 'n');                                        /**/
    
            end ( );                                                    /**/
    
            return 0;
    }
    
    void PigLatin(char *str)                                            /**/
    {
       char head = str[0];                                              /**/
       char temp = tolower ( head );                                    /**/
                                                                        /**/
        if ( temp == 'a' || temp == 'e' || temp == 'i' || temp == 'o' || temp == 'u' ){
                                                                        /**/
          while(*str)                                                   /**/
          if ( ispunct ( *str ) == 0 ) putchar(*str++);                 /**/
           else str++;
          printf("yay ");                                               /**/
       }
       else {
       str++;                                                           /**/
         while(*str)                                                    /**/
         if ( ispunct ( *str ) == 0 ) putchar(*str++);                  /**/
           else str++;
    
          printf("%cay ", head);                                        /**/
       }
       z = 0;                                                           /**/
       clear_temp ();                                                   /**/
       return;
    }
    
    void clear_temp ( void )                                            
    {                                                                   
      int w;                                                            
      for ( w = 0; w <= 24; w++)                                        /**/
          temp[w]=0;                                                    /**/
          return;                                                       
    }
    
    void end ( void )                                                   
    {                                                                   
            printf( "aterLay udeday!!!\n ");
            exit (0);
    }
    Last edited by noob2c; 04-06-2003 at 07:13 PM.

  2. #2
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    instead of this
    Code:
    do {
    
               char phrase[1000];                                       /**/
    
               
               printf( "Enter your dialog to be converted.");           /**/
               printf( "\n" );                                          /**/
               fflush ( stdin );                                        /**/
               gets( phrase );
    Dont use fflush input buffer like that .... go to the faq there are "nice" ways to flush input buffer.
    Dont use gets.... it doenst says how long phrase can be therefore.. your app might going crazy if the buffer is overwhelmed... therefore use fgets like this.
    Code:
    fgets(phrase,BUFSIZ,stdin);
    BUFSIZ is defined in stdio.h

    And you dont need to use BUFSIZ actually coz in the assignment there was a sentence stating this.
    You may assume that each English line will be 100 characters or less and each Pig Latin line will be 200 characters or less and each English word will be 17 characters or less and each Pig Latin word will be 20 characters or less.
    So what i would do use fgets then like this.
    Code:
    fgets(phrase, 200, stdin);
    Thats all i have to say ... about the strange output ... i dont really get what you mean, seems OK to me.
    Last edited by GanglyLamb; 04-06-2003 at 02:54 PM.

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    134
    the output for this statement in the assignment is

    line:- The black cat ate the mouse by a pond.
    pig latin- ehthay ackblay atcay ateway ehthay ousemay byway away ondpay.

    but this code spits out
    heTay lackbay atcay ateyay hetay ousemay ybay ayay ondpay

    I need to fix that
    Last edited by noob2c; 04-06-2003 at 03:53 PM.

  4. #4
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    Code:
     y = 0;                                                   /**/
               x = strlen ( phrase );                                   /**/
               z = 0;
    To make it yourself a lot easier i would suggest that you change the x into phrase_length. It may be a lil longer to type but you certainly wont forget what phrase_length represents, wich cant be said of a simple X.

    Btw about that output... wasnt that the whole point of the assignment.. Anyway ill check on that tomorow, coz its late and im tired (and im going to sleep in 5 mins).

  5. #5
    Registered User
    Join Date
    Mar 2003
    Posts
    134
    the two outputs are different...the one that is required by the assignment and the one put out by my command

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Open Source / Semi Open source game idea. Help needed
    By CaptainPatent in forum Projects and Job Recruitment
    Replies: 10
    Last Post: 05-16-2007, 10:44 AM
  2. Real Programmers.....in the old days
    By The SharK in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 07-27-2006, 04:29 PM
  3. %16 with double
    By spank in forum C Programming
    Replies: 11
    Last Post: 03-05-2006, 10:10 PM
  4. Why am I getting 'undelcared identifier' ???
    By Bill83 in forum C++ Programming
    Replies: 2
    Last Post: 02-15-2006, 01:00 PM
  5. Beckham in Real Madrid
    By Indian_fan in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 06-19-2003, 04:39 PM