Thread: Help with grouping & ignoring pronunciation

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    16

    Help with grouping & ignoring pronunciation

    I have this simple program that ciphers text.
    Original Alphabet: ABCDEFGHIJKLMNOPQRSTUVWXYZ
    Substitution Alphabet: GHIJKLMNOPQRSTUVWXYZABCDEF
    The program works for me but im having trouble editing my output.

    For example if I input the following statement:
    I came, I saw, I conquered!
    My current output is:
    O igsk, O ygc, O iutwakxkj!

    But I need to find a way to ignore the white space, and all of the punctuation, and then i also need to group the characters into 5.
    In other words i need the output to be:
    Oigsk OygcO iutwa kxkj

    Any tips on how to do this? I just started C programming and this is allready way out of my league!

    Can someone also look at my code to see if everything i have down is needed. I just put alot of stuff down, and im not sure if it all needs to be there, but it works :)

    Code:
    #include <stdio.h> 
    #include <ctype.h> 
    #define ESC 27  
    
    int main(){  /* function main */
    	int i;  /* declare a variable named i of type int */
    	char ch = 0; /* declare a variable named ch of type char */
    	char *alpha = "abcdefghijklmnopqrstuvwxyz";  /* declare a char pointer to the beginning of the alphabet */ 
    	char *key = "ghijklmnopqrstuvwxyzabcdef";  /* declare a char pointer to the beginning of the key */
    	while( ch != ESC ){  /* do the following while the escape character is not present */
    	ch = fgetc( stdin );  /* store a character entered from standard input into ch */
    	if( isalpha( ch ) ) {  /* do the following if ch is a letter */
                  	for( i = 0 ; i < 26 ; ++i ){  /* for( INIT ; LOOP WHILE THIS IS TRUE ; MANIPULATE ) */
                     	if( alpha[ i ] == tolower( ch ) ){  /* if the character residing at alpha + offset i = ch */
                        	ch = /* we're going to assign something to ch */
                        	( isupper( ch ) ) ?  /* is ch uppercase? */
                        	( toupper( key[ i ] ) ) : /* if so assign to ch the upercase version of key at offset i */
                        	key[ i ];  /* otherwise use the already lowercase defualt */
                        	break; /* break because we found it and no longer need to search */
                     	} /* end if block */
                 		} /* end for block */
    	}  /* end of if block */
    	fputc( ch, stdout );  /* put the character back to standard output */
    }
    return( 0 );  /* return control to the operating system */
    }  /* end main block */

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    16
    Thanks! Works like a charm!

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    7
    things like this really make me appreciate perl.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 04-03-2009, 04:16 PM
  2. Sort a string vector ignoring case
    By jw232 in forum C++ Programming
    Replies: 6
    Last Post: 02-01-2008, 01:37 AM
  3. Help ignoring spaces.
    By inmaterichard in forum C Programming
    Replies: 1
    Last Post: 07-25-2007, 08:00 PM
  4. Ignoring the Tab at the begining of the line..
    By NANO in forum C++ Programming
    Replies: 8
    Last Post: 05-03-2003, 10:56 PM
  5. ignoring repitions
    By BEEP BEEP in forum C Programming
    Replies: 4
    Last Post: 04-23-2003, 12:43 PM