sexta-feira, 30 de novembro de 2012

Matriz multidimensional de strings


Matriz de strings são Matrizes bidimensional de caracteres, onde uma Matriz bidimensional é uma das formas de Matriz Multidimensional.
Sendo duas dimensões, a dimensão do lado esquerdo se refere à quantidade de string e a dimensão da direita nos diz a respeito do comprimento máximo de cada string,
lembrando que o último caractere é o '\0', exigido.

Veja este simples exemplo abaixo:

Imagens:




Código:


#include <stdio.h>
#include <conio.h>
void Janela5(){
int lin, col;
col = 0;system("color B5");
for ( lin = 0; lin <= 25; lin++ ){
for ( col = 0; col <= 80; col++ ){
gotoxy( col, lin );
if ( lin == 2 ){textbackground(BLACK);printf( " ");}
if ( col == 1 ){textbackground(BLACK);printf(" ");}
if ( lin == 25 ){textbackground(BLACK);}
if ( col == 80 ){textbackground(BLACK);printf(" ");}
}
}textbackground(BLACK);
}
int continuando( ){
int nr; do{system("cls");Janela5();
textcolor(LIGHTRED);gotoxy(26,3);printf("MATRIZ MULTIDIMENSIONAL DE STRINGS");
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(22,9);printf ("Digite ");
textcolor(LIGHTRED);printf ("0");
textcolor(LIGHTBLUE);printf (" para sair ou " );
textcolor(LIGHTRED);printf ("1");
textcolor(LIGHTBLUE);printf (" para continuar : ");
textcolor(LIGHTRED);scanf ( "%d", &nr );fflush(stdin);fflush(stdin);
if( nr == 0 ){
textcolor(LIGHTRED);gotoxy(33,18);printf("O ROCCO AGRADECE!");
getche();exit(0);
}
else if( nr == 1 ){
return 1;
}
textcolor(YELLOW);gotoxy(37,16);printf ("\aopção errada!");
getche();
}while(1);
return 1;
}
int main(){
system("title MATRIZ MULTIDIMENSIONAL DE STRINGS");
char posicao [ 6 ] [ 18 ] = { "Melancia    ==> ", "Melão       ==> ", "Moranguinho ==> ",
"Pêra        ==> ", "Jaca        ==> ", "Banana      ==> " };
int i;
continuando();system("cls");Janela5();
textcolor(LIGHTRED);gotoxy(26,3);printf("MATRIZ MULTIDIMENSIONAL DE STRINGS");
textcolor(YELLOW);gotoxy(34,5);printf("sa_sp10@hotmail.com");
textcolor(LIGHTBLUE);gotoxy(36,7);printf("MULHERES FRUTAS");
for ( i = 0; i < 6; i++ ) {
gotoxy(25, i  + 9);
textcolor(LIGHTBLUE);printf(" Mulher ");
textcolor(YELLOW);printf(" %s", posicao [ i ] );
textcolor(LIGHTBLUE);printf(" Posição " );
textcolor(LIGHTRED);printf(" %d", i );
Sleep(800);
}
textcolor(LIGHTRED);gotoxy(30,16);printf("Banana ?? TOH FORA MANO ");
textcolor(LIGHTCYAN);gotoxy(36,23);printf("MUITO OBRIGADO");
getche();exit(0);
getche();
}



Nenhum comentário:

Postar um comentário

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