Thread: help needed immediately

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

    help needed immediately

    hi,
    I want to know how to modify this code so that i can do there?

    1. if there is any sort of punctuation, put that at the end of the converted word.
    2. if there is no vowel, add "way" to the end.

    Code:
    #include <stdio.h> 
    #include <stdlib.h> 
    #include <string.h> 
    #include <ctype.h> 
    
    static int isVowel ( char ch ) 
    { 
      ch = toupper ( ch ); 
      return ( ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U' ) ? 1 : 0; 
    }
    
    static char *transWord ( char *word ) 
    { 
      int i, j; 
      char temp[80]; memset ( temp, '\0', 80 );
      if ( isVowel ( word[0] ) ) {
        strcat ( word, "way" );
        return word;
      }
      else {
        for ( i = 0; !isVowel ( word[i] ); i++ ); 
        for ( j = 0; word[i] != '\0'; i++ ) 
          temp[j++] = ( ispunct(word[i]) ) ? '`' : word[i];
        for ( i = 0; !isVowel ( word[i] ); i++ ) 
          temp[j++] = tolower ( word[i] ); 
        strcat ( temp, "ay" ); strcpy ( word, temp );
      }
      return word; 
    } 
    
    int main ( void ) 
    { 
      char buffer[1024], final[1024], word[80], *temp;
      memset ( final, '\0', sizeof final );
      puts ( "Enter a phrase or sentence" ); 
      scanf ( "%1024[^\n]", buffer );
      temp = strtok ( buffer, " \0" ); 
      while ( temp != NULL ) {  
        strcpy ( word, temp );
        temp = transWord ( word ); 
        strcat ( final, temp ); strcat ( final, " " ); 
        temp = strtok ( NULL, " \0" ); 
      }
      final[0] = toupper ( final[0] ); puts ( final );
      return EXIT_SUCCESS; 
    }
    Last edited by noob2c; 04-11-2003 at 05:03 PM.

  2. #2
    Open to suggestions Brighteyes's Avatar
    Join Date
    Mar 2003
    Posts
    204
    1. if there is any sort of punctuation, put that at the end of the converted word.
    Really quick and crude, but I think this is what you wanted. If you want a better way, I'm sure you can figure it out.
    Code:
    static char *transWord ( char *word ) 
    { 
      int i, j; 
      char punc = 0;
      char temp[80]; memset ( temp, '\0', 80 );
      if ( isVowel ( word[0] ) ) {
        strcat ( word, "way" );
        return word;
      }
      else {
        for ( i = 0; !isVowel ( word[i] ); i++ ); 
        for ( j = 0; word[i] != '\0'; i++ )
        {
          if ( ispunct(word[i]) )
            punc = word[i];
          else
            temp[j++] = word[i];
        }
        for ( i = 0; !isVowel ( word[i] ); i++ ) 
          temp[j++] = tolower ( word[i] );
        strcat ( temp, "ay" ); 
        if ( punc != 0 )
          temp[j+2] = punc;
        strcpy ( word, temp );
      }
      return word; 
    }
    2. if there is no wel, add "way" to the end.
    It already does that.

    Of course, you could've just emailed the original author to see how they would have done it just as easily as posting here.
    p.s. What the alphabet would look like without q and r.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. free needed or not?
    By quantt in forum Linux Programming
    Replies: 3
    Last Post: 06-25-2009, 09:32 AM
  2. C Programmers needed for Direct Hire positions
    By canefan in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 09-24-2008, 11:55 AM
  3. C++ help needed
    By Enkindu in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 08-31-2004, 11:24 PM
  4. Using pointers - asterisks needed ?
    By Nutshell in forum C Programming
    Replies: 5
    Last Post: 01-28-2002, 06:56 PM