Com poucas modificações, más com melhorias no desempenho, apresento este progrrama que é a versão II
do programa: Unindo e Ordenando Vetor de caracteres.
Acompanhe abaixo nas imagens:
Veja o código abaixo:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <windows.h>
//#include "gottextback.DLL"
#define tam 26
void Janela5(){
int lin, col;system("color 2F");
for ( lin = 0; lin <= 36; lin++ ){
for ( col = 0; col <= 80; col++ ){
gotoxy( col, lin );
if ( lin == 2 ){textbackground(BLACK);printf( " ");}
if ( col == 1 ){textbackground(BLACK);printf(" ");}
if ( lin == 36 ){textbackground(BLACK);}
if ( col == 80 ){textbackground(BLACK);printf(" ");}
}
}textbackground( BLACK );
}
int Func_Uteis( int *n , int *m, char *Vetor, char *Vet, char *Vet_or, char *string );
int Func_Uteis_Dois( int *n, int *m, char *Vetor, char *Vet, char *Vet_or, char *string );
int Unin_Ord_Caracter( int *n, int *m, char *Vetor, char *Vet, char *Vet_or );
int Func_Uteis( int *n, int *m, char *Vetor, char *Vet, char *Vet_or, char *string ){
int i;
do{system("cls");Janela5();
textcolor(LIGHTRED);gotoxy(23,3); printf("UNINDO E ORDENANDO VETOR DE CARACTERES II");
textcolor(LIGHTBLUE);gotoxy(20,5);printf("Quantos Caracteres para o Vetor A ? ");
textcolor(YELLOW);
fgets( string, sizeof( string ), stdin );
if ( ( *string >= '0' ) && ( *string <= '9' ) ){
textcolor(LIGHTBLUE);gotoxy(20,7);printf("Você digitou");
textcolor(LIGHTRED);printf(" %s", string );
}
else{
textcolor(LIGHTBLUE);gotoxy(20,7);printf("Você digitou ");
textcolor(LIGHTRED);gotoxy(32,7);printf(" %s", string );
textcolor(LIGHTBLUE);gotoxy(34,7);printf(" Isto não e um dígito");
getche();Func_Uteis( n, m, Vetor, Vet, Vet_or, string );
}
getche();
n = ( int* ) malloc ( tam * sizeof ( int ) );
*n = atoi ( string );
if ( *n < 0 || *n > tam ){
gotoxy(20,14);printf("\aSó são aceitos Números Acima de 0 e menor que %d ", tam );
getche();system("cls");
}
}while ( ( *n < 0 ) || ( *n > tam ) ) ;
for ( i = 0; i < *n; i++ ){
system("cls");Janela5();
textcolor(LIGHTRED);gotoxy(23,3);printf("UNINDO E ORDENANDO VETOR DE CARACTERES II");
textcolor(LIGHTBLUE);gotoxy(18,5);printf("Digite um caractere para a posição " );
textcolor(LIGHTRED);printf(" %do ", i + 0 );
textcolor(LIGHTBLUE);printf("do Vetor A " );
textcolor(YELLOW);gotoxy(70, 5);
fgets( string, sizeof( string ), stdin );fflush(stdin);
Vetor [ i ] = *string;
Vet [ i ] = *string;
if ( ( *string >= '0' ) && ( *string <= '9' ) ){
textcolor(LIGHTBLUE);gotoxy(18,7);printf("Você digitou");
textcolor(LIGHTRED);gotoxy(31,7);printf(" %s", string );
textcolor(LIGHTBLUE);gotoxy(35,7);printf(" Números não são aceitos");
getche();Func_Uteis( n, m, Vetor, Vet, Vet_or, string );
break;
}
}
Func_Uteis_Dois( n, m, Vetor, Vet, Vet_or, string );
return(0);
}
int Func_Uteis_Dois( int *n, int *m, char *Vetor, char *Vet, char *Vet_or, char *string ){
int i;
do{system("cls");Janela5();
textcolor(LIGHTRED);gotoxy(23,3); printf("UNINDO E ORDENANDO VETOR DE CARACTERES II");
textcolor(LIGHTBLUE);gotoxy(20,5);printf("Quantos Caracteres para o Vetor B ? ");
textcolor(YELLOW);
fgets( string, sizeof( string ), stdin );fflush(stdin);
if ( ( *string >= '0' ) && ( *string <= '9' ) ){
textcolor(LIGHTBLUE);gotoxy(20,7);printf("Você digitou");
textcolor(LIGHTRED);printf(" %s", string );
}
else{
textcolor(LIGHTBLUE);gotoxy(20,7);printf("Você digitou ");
textcolor(LIGHTRED);gotoxy(32,7);printf(" %s", string );
textcolor(LIGHTBLUE);gotoxy(34,7);printf(" Isto não e um dígito");
getche();Func_Uteis_Dois( n, m, Vetor, Vet, Vet_or, string );
}
getche();
m = ( int* ) malloc ( tam * sizeof ( int ) );
*m = atoi ( string );
if ( *m < 0 || *m > tam ){
gotoxy(20,14);printf("\aSó são aceitos Números Acima de 0 e menor que %d ", tam );
getche();system("cls");
}
}while ( ( *m < 0 ) || ( *m > tam ) ) ;
for ( i = 0; i < *m; i++ ) {system("cls");Janela5();
textcolor(LIGHTRED);gotoxy(23,3);printf("UNINDO E ORDENANDO VETOR DE CARACTERES II");
textcolor(LIGHTBLUE);gotoxy(18,5);printf("Digite um caractere para a posição " );
textcolor(LIGHTRED);printf(" %do ", i + 0 );
textcolor(LIGHTBLUE);printf("do Vetor B " );
textcolor(YELLOW);gotoxy(70, 5);
fgets( string, sizeof( string ), stdin );fflush(stdin);
Vet_or [ i ] = *string;
Vet [ i + *n ] = *string;
if ( ( *string >= '0' ) && ( *string <= '9' ) ){
textcolor(LIGHTBLUE);gotoxy(18,7);printf("Você digitou");
textcolor(LIGHTRED);gotoxy(31,7);printf(" %s", string );
textcolor(LIGHTBLUE);gotoxy(35,7);printf(" Números não são aceitos");
getche();Func_Uteis_Dois( n, m, Vetor, Vet, Vet_or, string );
break;
}
}
Unin_Ord_Caracter( n, m, Vetor, Vet, Vet_or );
return(0);
}
void inicio( int *n, int *m, char *Vetor, char *Vet, char *Vet_or, char *string ){
int i;system("cls");do{Janela5();
textcolor(LIGHTRED);gotoxy(23,7);printf("UNINDO E ORDENANDO VETOR DE CARACTERES II");
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(41,16);
scanf("%d",&i);fflush(stdin);
if( i == 1 ){textcolor(LIGHTRED);gotoxy(30,20);printf ("MUITO OBRIGADO");Sleep(1800);exit(0);}
if( i == 2 ){system("cls"); Func_Uteis( n, m, Vetor, Vet, Vet_or, string );}
else {textcolor(LIGHTBLUE);gotoxy(37,20);printf ("\aOPÇÃO ERRADA");Sleep(1800);system("cls");}
}
while(i);
}
int Unin_Ord_Caracter( int *n, int *m, char *Vetor, char *Vet, char *Vet_or ){
int i;system("cls");Janela5();
textcolor(LIGHTRED);gotoxy(23,3);printf("UNINDO E ORDENANDO VETOR DE CARACTERES II ");
textcolor(YELLOW);gotoxy(27,5);printf("ESTES SÃO OS VETORES PREENCHIDOS");
textcolor(LIGHTBLUE);gotoxy(20,7);
printf("Mostrando abaixo os ");
textcolor(LIGHTRED);printf("%d", *n );
textcolor(LIGHTBLUE);printf(" Caracteres do Vetor A " );
textcolor(LIGHTRED);gotoxy(20,9);
for( i = 0; i < *n; i++ ){
printf(" %c ",Vetor [ i ] );
}
getche();
textcolor(LIGHTBLUE);gotoxy(20,11);
printf("Mostrando abaixo os ");
textcolor(LIGHTRED);printf("%d", *m );
textcolor(LIGHTBLUE);printf(" Caracteres do Vetor B " );
textcolor(LIGHTRED);gotoxy(20,13);
for( i = 0; i < *m; i++ ){
printf(" %c ",Vet_or [ i ] );
}
getche();
textcolor(LIGHTBLUE);gotoxy(10,15);
textcolor(LIGHTBLUE);printf("Mostrando abaixo os ");
textcolor(LIGHTRED);printf("%d", *n + *m );
textcolor(LIGHTBLUE);printf(" Caracteres do Vetor A + O Vetor B " );
textcolor(YELLOW);gotoxy(10,17);
for( i = 0; i < ( *n + *m ); i++ ){
printf(" %c ",Vet [ i ] );
}
getche();
textcolor(LIGHTBLUE);gotoxy(10,19);printf("Mostrando abaixo os ");
textcolor(LIGHTRED);printf("%d", *n + *m );
textcolor(LIGHTBLUE);printf(" Caracteres do Vetor A + O Vetor B Ordenados" );
textcolor(YELLOW);gotoxy(10,21);
register int a, b;
register char t;
for( a = 0; a < ( *n + *m ); ++a )
for( b = ( *n + *m ) -1; b >= a; --b ){
if( Vet [ b -1 ] > Vet [ b ] ){
/* troca os elementos */
t = Vet [ b -1 ];
Vet[ b -1 ] = Vet [ b ];
Vet [ b ] = t;
}
}
for( i = 0; i < ( *n + * m ); i++ ){
printf(" %c ", Vet [ i ] );
}
Sleep(1800);
textcolor(LIGHTRED);gotoxy(35,23);printf ("MUITO OBRIGADO");
getche();exit(0);
return(0);
}
int main(){
int *n = 0, *m = 0;
system ("title UNINDO E ORDENANDO VETOR DE CARACTERES II");
char Vetor [ tam ];char Vet_or [ tam ];char Vet [ tam ];char string [ 3 ];
inicio( n, m, Vetor, Vet, Vet_or, string );
return(0);
}
cteres
do programa: Unindo e Ordenando Vetor de caracteres.
Acompanhe abaixo nas imagens:
Veja o código abaixo:
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <windows.h>
//#include "gottextback.DLL"
#define tam 26
void Janela5(){
int lin, col;system("color 2F");
for ( lin = 0; lin <= 36; lin++ ){
for ( col = 0; col <= 80; col++ ){
gotoxy( col, lin );
if ( lin == 2 ){textbackground(BLACK);printf( " ");}
if ( col == 1 ){textbackground(BLACK);printf(" ");}
if ( lin == 36 ){textbackground(BLACK);}
if ( col == 80 ){textbackground(BLACK);printf(" ");}
}
}textbackground( BLACK );
}
int Func_Uteis( int *n , int *m, char *Vetor, char *Vet, char *Vet_or, char *string );
int Func_Uteis_Dois( int *n, int *m, char *Vetor, char *Vet, char *Vet_or, char *string );
int Unin_Ord_Caracter( int *n, int *m, char *Vetor, char *Vet, char *Vet_or );
int Func_Uteis( int *n, int *m, char *Vetor, char *Vet, char *Vet_or, char *string ){
int i;
do{system("cls");Janela5();
textcolor(LIGHTRED);gotoxy(23,3); printf("UNINDO E ORDENANDO VETOR DE CARACTERES II");
textcolor(LIGHTBLUE);gotoxy(20,5);printf("Quantos Caracteres para o Vetor A ? ");
textcolor(YELLOW);
fgets( string, sizeof( string ), stdin );
if ( ( *string >= '0' ) && ( *string <= '9' ) ){
textcolor(LIGHTBLUE);gotoxy(20,7);printf("Você digitou");
textcolor(LIGHTRED);printf(" %s", string );
}
else{
textcolor(LIGHTBLUE);gotoxy(20,7);printf("Você digitou ");
textcolor(LIGHTRED);gotoxy(32,7);printf(" %s", string );
textcolor(LIGHTBLUE);gotoxy(34,7);printf(" Isto não e um dígito");
getche();Func_Uteis( n, m, Vetor, Vet, Vet_or, string );
}
getche();
n = ( int* ) malloc ( tam * sizeof ( int ) );
*n = atoi ( string );
if ( *n < 0 || *n > tam ){
gotoxy(20,14);printf("\aSó são aceitos Números Acima de 0 e menor que %d ", tam );
getche();system("cls");
}
}while ( ( *n < 0 ) || ( *n > tam ) ) ;
for ( i = 0; i < *n; i++ ){
system("cls");Janela5();
textcolor(LIGHTRED);gotoxy(23,3);printf("UNINDO E ORDENANDO VETOR DE CARACTERES II");
textcolor(LIGHTBLUE);gotoxy(18,5);printf("Digite um caractere para a posição " );
textcolor(LIGHTRED);printf(" %do ", i + 0 );
textcolor(LIGHTBLUE);printf("do Vetor A " );
textcolor(YELLOW);gotoxy(70, 5);
fgets( string, sizeof( string ), stdin );fflush(stdin);
Vetor [ i ] = *string;
Vet [ i ] = *string;
if ( ( *string >= '0' ) && ( *string <= '9' ) ){
textcolor(LIGHTBLUE);gotoxy(18,7);printf("Você digitou");
textcolor(LIGHTRED);gotoxy(31,7);printf(" %s", string );
textcolor(LIGHTBLUE);gotoxy(35,7);printf(" Números não são aceitos");
getche();Func_Uteis( n, m, Vetor, Vet, Vet_or, string );
break;
}
}
Func_Uteis_Dois( n, m, Vetor, Vet, Vet_or, string );
return(0);
}
int Func_Uteis_Dois( int *n, int *m, char *Vetor, char *Vet, char *Vet_or, char *string ){
int i;
do{system("cls");Janela5();
textcolor(LIGHTRED);gotoxy(23,3); printf("UNINDO E ORDENANDO VETOR DE CARACTERES II");
textcolor(LIGHTBLUE);gotoxy(20,5);printf("Quantos Caracteres para o Vetor B ? ");
textcolor(YELLOW);
fgets( string, sizeof( string ), stdin );fflush(stdin);
if ( ( *string >= '0' ) && ( *string <= '9' ) ){
textcolor(LIGHTBLUE);gotoxy(20,7);printf("Você digitou");
textcolor(LIGHTRED);printf(" %s", string );
}
else{
textcolor(LIGHTBLUE);gotoxy(20,7);printf("Você digitou ");
textcolor(LIGHTRED);gotoxy(32,7);printf(" %s", string );
textcolor(LIGHTBLUE);gotoxy(34,7);printf(" Isto não e um dígito");
getche();Func_Uteis_Dois( n, m, Vetor, Vet, Vet_or, string );
}
getche();
m = ( int* ) malloc ( tam * sizeof ( int ) );
*m = atoi ( string );
if ( *m < 0 || *m > tam ){
gotoxy(20,14);printf("\aSó são aceitos Números Acima de 0 e menor que %d ", tam );
getche();system("cls");
}
}while ( ( *m < 0 ) || ( *m > tam ) ) ;
for ( i = 0; i < *m; i++ ) {system("cls");Janela5();
textcolor(LIGHTRED);gotoxy(23,3);printf("UNINDO E ORDENANDO VETOR DE CARACTERES II");
textcolor(LIGHTBLUE);gotoxy(18,5);printf("Digite um caractere para a posição " );
textcolor(LIGHTRED);printf(" %do ", i + 0 );
textcolor(LIGHTBLUE);printf("do Vetor B " );
textcolor(YELLOW);gotoxy(70, 5);
fgets( string, sizeof( string ), stdin );fflush(stdin);
Vet_or [ i ] = *string;
Vet [ i + *n ] = *string;
if ( ( *string >= '0' ) && ( *string <= '9' ) ){
textcolor(LIGHTBLUE);gotoxy(18,7);printf("Você digitou");
textcolor(LIGHTRED);gotoxy(31,7);printf(" %s", string );
textcolor(LIGHTBLUE);gotoxy(35,7);printf(" Números não são aceitos");
getche();Func_Uteis_Dois( n, m, Vetor, Vet, Vet_or, string );
break;
}
}
Unin_Ord_Caracter( n, m, Vetor, Vet, Vet_or );
return(0);
}
void inicio( int *n, int *m, char *Vetor, char *Vet, char *Vet_or, char *string ){
int i;system("cls");do{Janela5();
textcolor(LIGHTRED);gotoxy(23,7);printf("UNINDO E ORDENANDO VETOR DE CARACTERES II");
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(41,16);
scanf("%d",&i);fflush(stdin);
if( i == 1 ){textcolor(LIGHTRED);gotoxy(30,20);printf ("MUITO OBRIGADO");Sleep(1800);exit(0);}
if( i == 2 ){system("cls"); Func_Uteis( n, m, Vetor, Vet, Vet_or, string );}
else {textcolor(LIGHTBLUE);gotoxy(37,20);printf ("\aOPÇÃO ERRADA");Sleep(1800);system("cls");}
}
while(i);
}
int Unin_Ord_Caracter( int *n, int *m, char *Vetor, char *Vet, char *Vet_or ){
int i;system("cls");Janela5();
textcolor(LIGHTRED);gotoxy(23,3);printf("UNINDO E ORDENANDO VETOR DE CARACTERES II ");
textcolor(YELLOW);gotoxy(27,5);printf("ESTES SÃO OS VETORES PREENCHIDOS");
textcolor(LIGHTBLUE);gotoxy(20,7);
printf("Mostrando abaixo os ");
textcolor(LIGHTRED);printf("%d", *n );
textcolor(LIGHTBLUE);printf(" Caracteres do Vetor A " );
textcolor(LIGHTRED);gotoxy(20,9);
for( i = 0; i < *n; i++ ){
printf(" %c ",Vetor [ i ] );
}
getche();
textcolor(LIGHTBLUE);gotoxy(20,11);
printf("Mostrando abaixo os ");
textcolor(LIGHTRED);printf("%d", *m );
textcolor(LIGHTBLUE);printf(" Caracteres do Vetor B " );
textcolor(LIGHTRED);gotoxy(20,13);
for( i = 0; i < *m; i++ ){
printf(" %c ",Vet_or [ i ] );
}
getche();
textcolor(LIGHTBLUE);gotoxy(10,15);
textcolor(LIGHTBLUE);printf("Mostrando abaixo os ");
textcolor(LIGHTRED);printf("%d", *n + *m );
textcolor(LIGHTBLUE);printf(" Caracteres do Vetor A + O Vetor B " );
textcolor(YELLOW);gotoxy(10,17);
for( i = 0; i < ( *n + *m ); i++ ){
printf(" %c ",Vet [ i ] );
}
getche();
textcolor(LIGHTBLUE);gotoxy(10,19);printf("Mostrando abaixo os ");
textcolor(LIGHTRED);printf("%d", *n + *m );
textcolor(LIGHTBLUE);printf(" Caracteres do Vetor A + O Vetor B Ordenados" );
textcolor(YELLOW);gotoxy(10,21);
register int a, b;
register char t;
for( a = 0; a < ( *n + *m ); ++a )
for( b = ( *n + *m ) -1; b >= a; --b ){
if( Vet [ b -1 ] > Vet [ b ] ){
/* troca os elementos */
t = Vet [ b -1 ];
Vet[ b -1 ] = Vet [ b ];
Vet [ b ] = t;
}
}
for( i = 0; i < ( *n + * m ); i++ ){
printf(" %c ", Vet [ i ] );
}
Sleep(1800);
textcolor(LIGHTRED);gotoxy(35,23);printf ("MUITO OBRIGADO");
getche();exit(0);
return(0);
}
int main(){
int *n = 0, *m = 0;
system ("title UNINDO E ORDENANDO VETOR DE CARACTERES II");
char Vetor [ tam ];char Vet_or [ tam ];char Vet [ tam ];char string [ 3 ];
inicio( n, m, Vetor, Vet, Vet_or, string );
return(0);
}
cteres