sexta-feira, 30 de novembro de 2012

Programa Pesquisando Palavras

O segredo do código é a fnção "strcmp", Da biblioteca
string.h, que faz comparações entre duas strings,
cuja sintaxe é:

strcmp(string1,string2);

Zero é retornado, se as strings comparadas forem iguais, se por acaso a string1 for maior, um valor menor deve ser retornado, e se a string2 for maior a função possivelmente retornará um valor acima de zero.
O melhor disso, é que estas funções são muito fácil de se usar, porque na verdade são  funções prontas da biblioteca string.h, o que fazemos são simples adaptações pra que se enquadrem em nossos códigos.
O código apresentado é um verdadeiro achado para os que estão começando no mundo maravilhoso da linguagem C, usei alguns comandos fundamentais para um bom desemenho do programa, à saber, o break; o continue; do{ }whie(); enfim, taí pra quem se interessar, tudo funcionando perfeitamente, más isto não quer dizer que não possa ser ainda mais melhorado, más isto fica à cargo de quem quizer.


Veja algumas imagens do programa em execução:












Veja o código do programa abaixo:

#include <stdio.h>
#include <conio.h>
#include <time.h>
#include <ctype.h>
void Funcexit ( ) {
     system ( "cls" );
     time_t hora_atual;
     void Janela6 ( );
     Janela6 ( );
     textcolor ( LIGHTRED );
     gotoxy ( 27, 3 );
     printf ( "PROGRAMA PESQUISANDO PALAVRAS" );
     gotoxy ( 32, 11 );
     textcolor ( LIGHTBLUE );
     printf ( "OPERAÇÃO FINALIZADA" );
     gotoxy ( 2, 23 );
     Sleep ( 1800 );
     gotoxy ( 20, 13 );
     textcolor ( LIGHTCYAN );
     printf ( "MUITO OBRIGADO POR TER USADO ESTE PROGRAMA\n" );
     time ( &hora_atual );
     gotoxy ( 20, 15 );
     textcolor ( YELLOW );
     printf ( "A data e hora atuais são: %s", ctime ( &hora_atual ) );
     gotoxy ( 3, 24 );
     Sleep ( 2800 );
     exit ( 0 );
}
void HoraData ( ) {
     textbackground ( BLACK );
     gotoxy ( 6, 20 );
     printf ( "Data:" );
     system ( "date/t" );
     gotoxy ( 6, 21 );
     printf ( "Horas:" );
     system ( "time/t" );
}
void Janela5 ( ) {
     int lin, col;
     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 Janela6 ( ) {
     int lin, col;
     for ( lin = 2; lin <= 24; lin++ )
         for ( col = 3; col <= 78; col++ ) {
              gotoxy ( col, lin );
              textbackground ( 6 );
              printf ( " " );
         }
     for ( lin = 5; lin <= 21; lin++ )
         for ( col = 6; col <= 75; col++ ) {
              gotoxy ( col, lin );
              textbackground ( 16 );
              printf ( " " );
         }
}
void Pesquisa ( ) {
     int main ( );
     void HoraData ( );
     char s [ 80 ];
     int cont;
     system ( "cls" );
     Janela5 ( );
     HoraData ( );
     for ( cont = 0;; cont++ ) {
         textcolor ( LIGHTRED );
         gotoxy ( 28, 3 );
         printf ( "PROGRAMA PESQUISANDO PALAVRAS" );
         textcolor ( YELLOW );
         gotoxy ( 25, 5 );
         printf ( "Programa desenvolvido por:" );
         textcolor ( LIGHTCYAN );
         gotoxy ( 53, 5 );
         printf ( "Samuel Lima" );
         textcolor ( LIGHTGREEN );
         gotoxy ( 33, 7 );
         printf ( "sa_sp10@hotmail.com" );
         textcolor ( LIGHTBLUE );
         gotoxy ( 24, 9 );
         printf ( "DIGITE UMA PALAVRA PARA PESQUISAR : " );
         textcolor ( LIGHTRED );
         gets ( s );
         fflush ( stdin );
         textcolor ( LIGHTGREEN );
         gotoxy ( 29, 11 );
         printf ( "Verificando..." );
         Sleep ( 1000 );
         gotoxy ( 29, 11 );
         printf ( "                " );
         if ( ( strcmp ( strlwr ( s ), "abade" ) && strcmp ( s, "abalizar" )
                   && strcmp ( s, "abdutor" ) && strcmp ( s, "abespinhamento" )
                   && strcmp ( s, "aborbulhamento" ) && strcmp ( s, "adjacente" )
                   && strcmp ( s, "bacilo" ) && strcmp ( s, "baião" )
                   && strcmp ( s, "banalizar" ) && strcmp ( s, "barcarola" )
                   && strcmp ( s, "carbalístico" ) && strcmp ( s, "caceteação" )
                   && strcmp ( s, "caco" ) && strcmp ( s, "catinga" )
                   && strcmp ( s, "ecológo" ) ) ) {
              textcolor ( LIGHTBLUE );
              gotoxy ( 20, 11 );
              printf ( "\aESTA PALAVRA" );
              textcolor ( LIGHTRED );
              gotoxy ( 33, 11 );
              printf ( "%s", s );
              textcolor ( LIGHTBLUE );
              gotoxy ( 20, 13 );
              printf ( "NÃO ESTA CADASTRADA" );
              Sleep ( 1800 );
              break;
              system ( "cls" );
         }
         if ( strcmp ( s, "" ) ) {
              textcolor ( YELLOW );
              gotoxy ( 20, 13 );
              printf ( "FOI ENCONTRADA" );
              textcolor ( LIGHTRED );
              gotoxy ( 39, 13 );
              printf ( "%s", s );
              textcolor ( LIGHTBLUE );
              Sleep ( 1800 );
              break;
         }
     }
}
void Ver ( ) {
     void HoraData ( );
     int i;
     char posicao [ 14 ] [ 15 ] = { "ABADE", "ABALIZAR", "ABDUTOR",
              "ABESPINHAMENTO", "ADJACENTE", "BACILO", "BAIÃO", "BANALIZAR",
              "BARCAROLA", "CABALÍSTICO", "CACETEAÇÃO", "CACO", "CATINGA",
              "ECÓLOGO" };
     system ( "cls" );
     Janela5 ( );
     HoraData ( );
     textcolor ( LIGHTRED );
     gotoxy ( 27, 3 );
     printf ( "PROGRAMA PESQUISANDO PALAVRAS" );
     textcolor ( LIGHTBLUE );
     gotoxy ( 35, 5 );
     printf ( "sa_sp10@hotmail.com" );
     textcolor ( YELLOW );
     gotoxy ( 27, 7 );
     printf ( "palavras Cadastradas" );
     textcolor ( LIGHTCYAN );
     for ( i = 0;; i++ ) {
         for ( i = 0; i < 14; i++ ) {
              gotoxy ( 25, i + 9 );
              printf ( "%s", posicao [ i ] );
              Sleep ( 800 );
         }
         getche ( );
         break;
     }
}
int main ( ) {
     system ( "title PROGRAMA PESQUISANDO PALAVRAS" );
     char P [ 10 ];
     char ch;
     do {
         system ( "cls" );
         Janela6 ( );
         HoraData ( );
         textcolor ( LIGHTRED );
         gotoxy ( 28, 8 );
         printf ( "PROGRAMA PESQUISANDO PALAVRAS" );
         textcolor ( YELLOW );
         gotoxy ( 25, 10 );
         printf ( "Programa desenvolvido por:" );
         textcolor ( LIGHTCYAN );
         gotoxy ( 52, 10 );
         printf ( "Samuel Lima" );
         textcolor ( LIGHTGREEN );
         gotoxy ( 33, 12 );
         printf ( "sa_sp10@hotmail.com" );
         textcolor ( LIGHTBLUE );
         gotoxy ( 23, 14 );
         printf ( "DIGITE    PARA SAIR OU     PARA CONTINUAR  " );
         textcolor ( LIGHTRED );
         gotoxy ( 31, 14 );
         printf ( "S" );
         textcolor ( LIGHTRED );
         gotoxy ( 47, 14 );
         printf ( "C" );
         gotoxy ( 31, 16 );
         textcolor ( YELLOW );
         ch = getche ( );
         fflush ( stdin );
         if ( toupper ( ch ) == 'S' ) {
              textcolor ( LIGHTBLUE );
              Funcexit ( );
         } else if ( toupper ( ch ) == 'C' ) {
              system ( "cls" );
              Janela5 ( );
              HoraData ( );
              textcolor ( LIGHTRED );
              gotoxy ( 28, 5 );
              printf ( "PROGRAMA PESQUISANDO PALAVRAS" );
              textcolor ( LIGHTBLUE );
              gotoxy ( 33, 7 );
              printf ( "sa_sp10@hotmail.com" );
              textcolor ( LIGHTGREEN );
              gotoxy ( 34, 9 );
              printf ( "DIGITE NO TECLADO " );
              textcolor ( LIGHTRED );
              gotoxy ( 20, 11 );
              printf ( "[ PES ]" );
              textcolor ( LIGHTCYAN );
              gotoxy ( 27, 11 );
              printf ( " Para Pesquisar uma Palavra" );
              textcolor ( LIGHTRED );
              gotoxy ( 20, 13 );
              printf ( "[ VER ]" );
              textcolor ( LIGHTCYAN );
              gotoxy ( 27, 13 );
              printf ( " Para Ver as palavras Cadastradas" );
              textcolor ( LIGHTRED );
              gotoxy ( 20, 15 );
              printf ( "[ FIM ]" );
              textcolor ( LIGHTCYAN );
              gotoxy ( 27, 15 );
              printf ( " Para terminar o Programa" );
              textcolor ( LIGHTRED );
              gotoxy ( 29, 17 );
              textcolor ( YELLOW );
              gets ( P );
              if ( ( strcmp ( strlwr ( P ), "fim" ) == 0 ) ) {
                   textcolor ( LIGHTBLUE );
                   Funcexit ( );
              }
              if ( ( strcmp ( strlwr ( P ), "ver" ) == 0 ) ) {
                   Ver ( );
              }
              if ( ( strcmp ( strlwr ( P ), "pes" ) == 0 ) ) {
                   Pesquisa ( );
              }
              if ( strcmp ( P, "fim" ) && strcmp ( P, "ver" )
                        && strcmp ( P, "pes" ) ) {
                   textcolor ( LIGHTBLUE );
                   gotoxy ( 37, 21 );
                   printf ( "\aOPÇÃO ERRADA !" );
                   Sleep ( 1800 );
                   continue;
                   system ( "cls" );
              }
         } else {
              textcolor ( LIGHTRED );
              gotoxy ( 36, 19 );
              printf ( "\aOPÇÃO ERRADA !" );
              Sleep ( 1800 );
         }
     } while ( 1 );
}

Nenhum comentário:

Postar um comentário

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