quarta-feira, 9 de abril de 2014

Passando string como parâmetros em Linguagem C

A primeira função que é invocada pela função principal e a função continuando(); que contem poucas informações sobre o autor do programa que sou eu mesmo.
A próxima chamada e para função Imprimindo_String(...); que recebe duas string de ponteiro para char como parâmetros, que são *Str e *str3.Nesta função, temos uma sequência numérica declarada e copiada em *str; e logo abaixo *str3 recebe esta mesma cópia dos números sequenciais de 1 até 10, que serão usados pela função Imprime_String( ... );
A função Imprime_String( ... ); é a segunda a ser chamada, e a string ponteiro *str, é a primeira a trabalhar, e já vai recebendo a cópia do nosso alfabeto em maiúsculo, e enviando para que seja imprimida por printf();
Más, não posso crescer muito o tópico, tornando-o chato,por isso, encerro os comentários e deixo aos cuidados à quem se interessar pelo código.

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






Veja este excelente código abaixo:

#include <string.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.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);
}
int continuando( ){
 int nr; do{system("cls");Janela5();
 textcolor(LIGHTRED);gotoxy(26,3);printf("PASSANDO STRING COMO PARAMETROS");
 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(33,18);printf("O ROCCO AGRADECE!");
  getche();exit(0);
 }
 else if( nr == 1 ){
  return 1;
 }
 textcolor(YELLOW);gotoxy(26,16);printf ("\aopcao errada!");
 getche();
 }while(1);
 return 1;
}
void Imprime_String( char* str, char *str1, char *str2, char *str3 ){
 int a, j;
 unsigned int i;
 strcpy(str,"ABCDEFGHIJKLMNOPQRSTUVXZWY");
 textcolor(LIGHTBLUE);gotoxy(10,13);printf("Abaixo, os  %d Caracteres do alfabeto Maiusculo ", a = strlen( str ) );
 textcolor(YELLOW);gotoxy(2,15);
 for ( i = 0; i < strlen( str ); i++ ){;
 printf(" %c ", str [ i ] );
 strcpy( str1, str );
 }
 getche();
 textcolor(LIGHTBLUE);gotoxy(10,17);printf("Abaixo, os  %d Caracteres do alfabeto Minusculo ", a = strlen( str ) );
 textcolor(YELLOW);gotoxy(2,19);
 strlwr ( str1 )  ;
 for ( i = 0; i < strlen( str1 ); i++ ){
  printf(" %c ", str1 [ i ] );
  strcpy( str2,  str1 );
 }
 getche();
 textcolor(LIGHTRED);gotoxy(28,21);printf("PRESSIONE QUALQUER TECLA" );
 getche();
 strupr ( str1 );strlwr ( str2 );
 strcat( str1,  str2 );system("cls");
 textcolor(LIGHTRED);gotoxy(26,3);printf("PASSANDO STRING COMO PARAMETROS");
 textcolor(LIGHTBLUE);gotoxy(10,5);printf("Abaixo, os  %d Caracteres do alfabeto Maiusculo e Minusculo ", a = strlen( str1 ) );
 textcolor(YELLOW);gotoxy(2,7);
 for ( i = 0; i < strlen( str1 ); i++ ){
  printf(" %c ", str1 [ i ] );
 }
 getche();
 for ( i = 0; i < strlen( str1 ); i++ ){
  j = i + rand() % ( strlen( str1 ) - i  );
  char t = str1 [ j ];
  str1 [ j ] = str1 [ i ];
  str1 [ i ] = t;
 }
 textcolor(LIGHTBLUE);gotoxy(6,10);printf("Abaixo, os  %d Caracteres do alfabeto Maiusculo e Minusculo Embaralhados", a = strlen( str1 ) );
 textcolor(YELLOW);gotoxy(2,12);
 for ( i = 0; i < strlen( str1 ); i++ ){
  printf(" %c ", str1 [ i ] );
 }
 getche();
 textcolor(LIGHTRED);gotoxy(28,21);printf("PRESSIONE QUALQUER TECLA" );
 getche();
 system("cls");Janela5();
 textcolor(LIGHTRED);gotoxy(26,3);printf("PASSANDO STRING COMO PARAMETROS");
 strcat( str3, str1 );
 textcolor(LIGHTBLUE);gotoxy(14,5);printf("Abaixo, todos os Elementos Concatenados e Embaralhados ");
 for ( i = 0; i < strlen( str3 ); i++ ){
  j = i + rand() % ( strlen( str3 ) - i  );
  char t = str3 [ j ];
  str3 [ j ] = str3 [ i ];
  str3 [ i ] = t;
 }
 textcolor(YELLOW);gotoxy(24,7);
 for ( i = 0; i < 10; i++ ){
  printf(" %c ", str3 [ i ] );
 }
 gotoxy(24,9);
 for ( i = 10; i < 20; i++ ){
  printf(" %c ", str3 [ i ] );
 }
 gotoxy(24,11);
 for ( i = 20; i < 30; i++ ){
  printf(" %c ", str3 [ i ] );
 }
 gotoxy(24,13);
 for ( i = 30; i < 40; i++ ){
  printf(" %c ", str3 [ i ] );
 }
 gotoxy(24,15);
 for ( i = 40; i < 50; i++ ){
  printf(" %c ", str3 [ i ] );
 }
 gotoxy(24,17);
 for ( i = 50; i < 62; i++ ){
  printf(" %c ", str3 [ i ] );
 }
 textcolor(LIGHTRED);gotoxy(36,21);printf("MUITO OBRIGADO");
 getche();
}
void Imprimindo_String( char* str, char *str3 ){
 int j, a;
 unsigned int i;
 strcpy(str,"1234567890");
 strcpy( str3,  str  );
 system("cls");Janela5();
 textcolor(LIGHTRED);gotoxy(26,3);printf("PASSANDO STRING COMO PARAMETROS");
 textcolor(LIGHTBLUE);gotoxy(10,5);printf("Abaixo, a Sequencia Numerica de 1 a %d Numeros", a = strlen( str ) );
 textcolor(YELLOW);gotoxy(2,7);
 for ( i = 0; i < strlen( str ); i++ ){
  printf(" %c ", str [ i ] );
 }
 getche();
 for (i = 0; i < strlen( str ); i++ ){
  j = i + rand() %  ( strlen( str ) - i );
  char t = str [ j ];
  str [ j ] = str [ i ];
  str [ i ] = t;
 }
 textcolor(LIGHTBLUE);gotoxy(10,9);printf("Abaixo, a Sequencia Numerica com seus  %d Numeros Embaralhados", a = strlen( str ) );
 textcolor(YELLOW);gotoxy(2,11);
 for ( i = 0; i < strlen( str ); i++ ){
  printf(" %c ", str [ i ] );
 }
 getche();
}
int main(){
 system ("title PASSANDO STRING COMO PARAMETROS");
 char str [ 20 ];char str1 [ 20 ];char str2 [ 20 ];char str3 [ 20 ];
 continuando( );
 Imprimindo_String ( str, str3 );
 Imprime_String( str, str1, str2, str3 );
 return(0);
}


 

Nenhum comentário:

Postar um comentário

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