sábado, 22 de fevereiro de 2014

Removendo Caractere de String

Sábado lindo por aqui, más não devo sair apesar do dia ser propício pra isto. A semana foi de muito trabalho, prefiro
descansar e relachar, fazendo o que mais gosto, programar em Linguagem C. Vi um tópico interessante aqui no forum e me interessei, então decidi, vou criar minha versão de um programa como este aproveitando meu tempo que me sobrou.
Mais não encontrei nenhuma moleza, e foi um pouco tedioso criar
este programa e deixá-lo funcionando satisfatoriamente como ficou. O código ficou em tanto extenso por causa dos detalhes
da interface do dos, usando as funções textcolor(); e gotoxy();
Porém, saiu como esperado, funcionando muito bem, criado no eclipse e rodando sem nenhum warnings.



Veja o código abaixo:

#include <stdio.h>
#include <string.h>
#include <conio.h>
void Janela5 ( ) {
     int lin, col;
     col = 0;
     for ( lin = 0; lin <= 25 ; lin++ ) {
         for ( col = 0; col <= 80 ; col++ ) {
              gotoxy ( col , lin );
              if ( lin == 2 ) {
                   textbackground ( LIGHTBLUE );
                   printf ( " " );
              }
              if ( col == 1 ) {
                   textbackground ( LIGHTBLUE );
                   printf ( " " );
              }
              if ( lin == 25 ) {
                   textbackground ( LIGHTBLUE );
              }
              if ( col == 80 ) {
                   textbackground ( LIGHTBLUE );
                   printf ( " " );
              }
         }
     }
     textbackground ( BLACK );
}
void Remove_String ( );
int main ( );
void inicio ( ) {
     system ( "title REMOVENDO CARACTERE DE STRING" );
     int i;
     system ( "cls" );
     do {
         Janela5 ( );
         textcolor ( LIGHTRED );
         gotoxy ( 30 , 7 );
         printf ( "REMOVENDO CARACTERE DE STRING" );
         textcolor ( YELLOW );
         gotoxy ( 25 , 10 );
         printf ( "Programa desenvolvido por:" );
         textcolor ( LIGHTCYAN );
         gotoxy ( 52 , 10 );
         printf ( "Samuel Lima" );
         textcolor ( LIGHTGREEN );
         gotoxy ( 34 , 12 );
         printf ( "sa_sp10@hotmail.com" );
         textcolor ( LIGHTBLUE );
         gotoxy ( 24 , 14 );
         printf ( "DIGITE    PARA SAIR OU   PARA CONTINUAR  " );
         textcolor ( LIGHTRED );
         gotoxy ( 32 , 14 );
         printf ( "1" );
         textcolor ( LIGHTRED );
         gotoxy ( 47 , 14 );
         printf ( "2" );
         gotoxy ( 21 , 16 );
         scanf ( "%d" , &i );
         fflush ( stdin );
         if ( i == 1 ) {
              textcolor ( LIGHTRED );
              gotoxy ( 30 , 20 );
              printf ( "O ROCCO AGRADECE" );
              Sleep ( 1800 );
              exit ( 0 );
         }
         if ( i == 2 ) {
              system ( "cls" );
              Remove_String ( );
         } else {
              textcolor ( LIGHTBLUE );
              gotoxy ( 30 , 20 );
              printf ( "\aOPCAO ERRADA" );
              Sleep ( 1800 );
              system ( "cls" );
         }
     } while ( i );
}
void Remove_String ( ) {
     char str [ 20 ], subs [ 20 ], Pala_vra [ 20 ], Palavra [ 10 ], *rem_ove;
     int rem, dim, i;
     system ( "title REMOVENDO CARACTERE DE STRING" );
     system ( "cls" );
     Janela5 ( );
     textcolor ( LIGHTRED );
     gotoxy ( 28 , 3 );
     printf ( "REMOVENDO CARACTERE DE STRING" );
     textcolor ( LIGHTBLUE );
     gotoxy ( 28 , 5 );
     printf ( "Digite uma Palavra: " );
     textcolor ( YELLOW );
     scanf ( "%50[^\n]" , str );
     fflush ( stdin );
     textcolor ( LIGHTBLUE );
     gotoxy ( 28 , 7 );
     printf ( "Voce digitou ==>" );
     textcolor ( LIGHTRED );
     gotoxy ( 48 , 7 );
     printf ( "%s" , str );
     textcolor ( LIGHTBLUE );
     gotoxy ( 28 , 9 );
     printf ( "Digite um Caractere: " );
     textcolor ( YELLOW );
     scanf ( "%s" , subs );
     fflush ( stdin );
     textcolor ( LIGHTBLUE );
     gotoxy ( 28 , 11 );
     printf ( "Voce digitou ==>" );
     textcolor ( LIGHTRED );
     gotoxy ( 48 , 11 );
     printf ( "%s" , subs );
     dim = strlen ( subs );
     rem_ove = strstr ( str , subs );
     if ( rem_ove ) {
         textcolor ( LIGHTBLUE );
         gotoxy ( 26 , 13 );
         printf ( "A Palavra contem o Caractere " );
         textcolor ( LIGHTRED );
         gotoxy ( 56 , 13 );
         printf ( "%s " , subs );
         textcolor ( LIGHTBLUE );
         gotoxy ( 26 , 14 );
         printf ( "O Caractere" );
         textcolor ( LIGHTRED );
         gotoxy ( 37 , 14 );
         printf ( " %s " , subs );
         textcolor ( LIGHTBLUE );
         gotoxy ( 41 , 14 );
         printf ( "esta na posicao" );
         textcolor ( LIGHTRED );
         gotoxy ( 57 , 14 );
         printf ( "%d" , rem_ove - str );
         textcolor ( LIGHTBLUE );
         gotoxy ( 59 , 14 );
         printf ( "da Palavra" );
         textcolor ( LIGHTGREEN );
         gotoxy ( 26 , 16 );
         printf ( "Deseja remover o Caractere" );
         textcolor ( LIGHTRED );
         gotoxy ( 54 , 16 );
         printf ( "%s" , subs );
         textcolor ( LIGHTGREEN );
         gotoxy ( 57 , 16 );
         printf ( "???" );
         {
              do {
                   textcolor ( LIGHTBLUE );
                   gotoxy ( 26 , 18 );
                   printf ( "Digite [ 1 para sim ] OU [ 0 para sair ]" );
                   textcolor ( YELLOW );
                   gotoxy ( 30 , 20 );
                   scanf ( "%d" , &rem );
                   fflush ( stdin );
                   if ( rem == 0 ) {
                        textcolor ( LIGHTRED );
                        gotoxy ( 30 , 20 );
                        printf ( "O ROCCO AGRADECE" );
                        Sleep ( 1800 );
                        exit ( 0 );
                   }
                   if ( rem == 1 ) {
                        strcpy ( Palavra , Pala_vra );
                        for ( i = 0; i < dim ; i++ )
                            str [ ( rem_ove - str ) + i ] = Pala_vra [ i ] = ' ';
                        textcolor ( LIGHTBLUE );
                        gotoxy ( 24 , 20 );
                        printf ( "\aO Caractere" );
                        textcolor ( LIGHTRED );
                        gotoxy ( 36 , 20 );
                        printf ( "%s" , subs );
                        textcolor ( LIGHTBLUE );
                        gotoxy ( 38 , 20 );
                        printf ( "foi removido com sucesso " );
                        textcolor ( LIGHTBLUE );
                        gotoxy ( 30 , 22 );
                        printf ( "Veja como ficou ==> " );
                        textcolor ( LIGHTRED );
                        gotoxy ( 52 , 22 );
                        printf ( "%s " , str );
                        getche ( );
                        main ( );
                   } else {
                        textcolor ( LIGHTBLUE );
                        gotoxy ( 30 , 20 );
                        printf ( "\aOPCAO ERRADA" );
                        getche ( );
                        textcolor ( LIGHTBLUE );
                        gotoxy ( 30 , 20 );
                        printf ( "                 " );
                   }
              } while ( 1 );
         }
     } else {
         textcolor ( LIGHTBLUE );
         gotoxy ( 30 , 22 );
         printf ( "\aA Palavra nao contem o Caractere %s" , subs );
         getche ( );
         Remove_String ( );
         system ( "cls" );
     }
}
int main ( ) {
     inicio ( );
}