sábado, 17 de maio de 2014

Lendo Matriz de String por um Arquivo e Ordenando II


Mais um programa no qual se lê uma matriz de string por
um arquivo de texto, só que desta vez a ordenação é sem
função, é feita no braço, más não foi fácil chegar a estes
ótimos resultados, porém, valeu a pena.

//Salve os nomes abaixos num arquivo de texto, com o nome de: Nomes.txt
 /*
 Eder Costa
Humberto Gomes
Dijalma Lacerda
Caroline Silva
Igor Goncalves
Bruna Carla
Fabio Quadros
Geany Barros
Jaqueline Vega
Ana Celia
  */

Veja abaixo algumas imagens do programa em execução:




Teste o programa abaixo e seja feliz:

#include <stdio.h>
#include <string.h>
#include <conio.h>
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 );
}
int continuando( ){
int nr; do{system("cls");Janela5();
system ("title MATRIZ DE STRING POR UM ARQUIVO E ORDENANDO II");
textcolor(LIGHTRED);gotoxy(20,3);printf("MATRIZ DE STRING POR UM ARQUIVO E ORDENANDO II");
textcolor(YELLOW);gotoxy(24,5);printf("Programa desenvolvido por:");
textcolor(LIGHTGRAY);gotoxy(51,5);printf("Samuel Lima");
textcolor(LIGHTGREEN);gotoxy(34,7);printf("sa_sp10@hotmail.com");
textcolor(LIGHTBLUE);gotoxy(24,9);printf ("Digite 0 para sair ou 1 para continuar ");
textcolor(LIGHTRED);scanf ( "%d", &nr );fflush(stdin);fflush(stdin);
if( nr == 0 ){
textcolor(LIGHTRED);gotoxy(35,21);printf("MUITO OBRIGADO");
getche();exit(0);
}
else if( nr == 1 ){
return 1;
}
textcolor(YELLOW);gotoxy(36,16);printf ("\aopcao errada!");
getche();
}while(1);
return 1;
}
int main(){
char matriz [ 10 ] [ 17 ];
char nome [ 10 ] [ 17 ], temp [ 17 ];
int i, j;
char *resul;
FILE *arq = fopen("Nomes.txt", "r" );
if ( arq == NULL ){
textcolor(YELLOW);gotoxy(26,12);
printf("Problemas na abertura do arquivo ");
getche();
return (0);
}
continuando();system("cls");Janela5();
textcolor(LIGHTRED);gotoxy(17,3);printf("MATRIZ DE STRING POR UM ARQUIVO E ORDENANDO II");
textcolor(LIGHTBLUE);gotoxy(6,5);printf("MATRIZ TXT DESORDENADA");
textcolor(WHITE);
for ( i = 0; i < 10; i++ ) {
gotoxy(5, i  + 7);
resul = fgets(*matriz, 17, arq);
strcpy( nome [ i ], *matriz);
printf(" %s ", *matriz );
}
fclose(arq);
getche();
textcolor(LIGHTBLUE);gotoxy(46,5);printf("MATRIZ TXT ORDENADA ");
for (i = 0; i < 9; i++){
for ( j = i + 1; j < 10; j++){
if (strcmp( nome [ i ], nome [ j ] ) > 0){
strcpy( temp, nome [ i ] );
strcpy( nome [ i ], nome [ j ] );
strcpy( nome [ j ], temp );
}
}
}textcolor(WHITE);
for (i = 0; i < 10; i++){
gotoxy(45, i  + 7);
printf(" %s ",nome [ i ] );
}Sleep(1800);
textcolor(LIGHTRED);gotoxy(35,21);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.