sábado, 29 de agosto de 2015

Frases - removendo consoantes

Neste exemplo, mostro como remover consoantes
de uma frase digitada pelo usuário facilmente,
copie o código e cole na sua IDE favorita;
Compile, e guarde-o para estudos.
O programa é indicado a iniciantes em Linguagem C.

Veja abaixo uma imagem do programa em execução:



Veja abaixo o código do programa em execução:


#include <stdio.h>
#include <conio.h>
void Janela5 ( ) {
     int lin, col;
     col = 0;
     system ( "Color 10" );
     for ( lin = 2; lin <= 24; lin++ )
         for ( col = 2; col <= 78; col++ ) {
              gotoxy ( col, lin );
              textbackground ( YELLOW );
              printf ( " " );
         }
}
int continuando ( ) {
     int nr;
     do {
         system ( "Color 90" );
         Janela5 ( );
         textcolor ( LIGHTRED );
         gotoxy ( 30, 3 );
         printf ( "FRASES - REMOVENDO CONSOANTES " );
         textcolor ( BROWN );
         gotoxy ( 25, 7 );
         printf ( "Programa desenvolvido por:" );
         textcolor ( GREEN );
         gotoxy ( 52, 7 );
         printf ( "Samuel Lima" );
         textcolor ( BLACK );
         gotoxy ( 34, 9 );
         printf ( "sa_sp10@hotmail.com" );
         textcolor ( LIGHTBLUE );
         gotoxy ( 23, 11 );
         printf ( "Digite " );
         textcolor ( LIGHTRED );
         printf ( " 0 " );
         textcolor ( LIGHTBLUE );
         printf ( " para sair ou " );
         textcolor ( LIGHTRED );
         printf ( " 1 " );
         textcolor ( LIGHTBLUE );
         printf ( " para continuar " );
         textcolor ( LIGHTRED );
         gotoxy ( 24, 13 );
         scanf ( "%d", &nr );
         fflush ( stdin );
         if ( nr == 0 ) {
              textcolor ( LIGHTRED );
              gotoxy ( 36, 18 );
              printf ( "MUITO OBRIGADO" );
              getche ( );
              exit ( 0 );
         } else if ( nr == 1 ) {
              return 1;
         }
         textcolor ( BLACK );
         gotoxy ( 36, 16 );
         printf ( "\aopcão errada!" );
         getche ( );
     } while ( 1 );
     return 1;
}
int main ( ) {
     system ( "title FRASES - REMOVENDO CONSOANTES" );
     continuando ( );
     system ( "cls" );
     Janela5 ( );
     unsigned int cont, i, j, len_v;
     char conso_antes [ ] = "bcdfghjklmnpqrstvwxyzBCDFGHJLMNPQRSTVWXYZ";
     len_v = strlen ( conso_antes );
     char str [ 255 ];
     textcolor ( LIGHTRED );
     gotoxy ( 30, 3 );
     printf ( "FRASES - REMOVENDO CONSOANTES " );
     textcolor ( LIGHTBLUE );
     gotoxy ( 20, 5 );
     printf ( "Digite uma frase ==> " );
     textcolor ( BLACK );
     gets ( str );
     textcolor ( LIGHTBLUE );
     gotoxy ( 20, 7 );
     printf ( "Frase digitada ==> " );
     textcolor ( BLACK );
     printf ( " %s", str );
     cont = 0;
     for ( i = 0; i <= strlen ( str ); i++ )
         for ( j = 0; j <= strlen ( conso_antes ); j++ )
              if ( str [ i ] == conso_antes [ j ] && str [ i ] != 0 )
                   cont++;
     textcolor ( LIGHTBLUE );
     gotoxy ( 20, 9 );
     printf ( "No nome ==> " );
     textcolor ( BLACK );
     printf ( "%s ", str );
     textcolor ( LIGHTBLUE );
     gotoxy ( 20, 11 );
     printf ( "Foram encontrados " );
     textcolor ( LIGHTRED );
     printf ( " %d ", cont );
     textcolor ( LIGHTBLUE );
     printf ( " consoantes" );
     textcolor ( LIGHTBLUE );
     gotoxy ( 20, 13 );
     printf ( "Mostrando abaixo o Nome ==> " );
     textcolor ( BLACK );
     printf ( "%s", str );
     textcolor ( LIGHTBLUE );
     gotoxy ( 20, 15 );
     printf ( "Sem suas consoantes ==> " );
     for ( i = 0; i < strlen ( str ); i++ ) {
         for ( j = 0; j < len_v; j++ )
              if ( str [ i ] == conso_antes [ j ] )
                   break;
         if ( j == len_v ) {
              textcolor ( BLACK );
              printf ( " %c", str [ i ] );
         }
     }
     Sleep ( 1000 );
     textcolor ( LIGHTRED );
     gotoxy ( 36, 23 );
     printf ( "MUITO OBRIGADO" );
     getche ( );
     return ( 0 );
}

Nenhum comentário:

Postar um comentário

Observação: somente um membro deste blog pode postar um comentário.