Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.54 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <string.h>
  4. #include <locale.h>
  5.  
  6. char options();
  7. void readRG();
  8. void findRG(int d);
  9.  
  10. char listRG[20][10];
  11. int nextRG;
  12.  
  13. int main(){
  14.     char opt='3';
  15.     int num;
  16.  
  17.     setlocale(LC_ALL, "Portuguese");
  18.  
  19.     nextRG = 0;
  20.  
  21.     while (opt!='5'){
  22.         opt = options();
  23.  
  24.         switch (opt){
  25.             case '1':
  26.                 readRG();
  27.                 break;
  28.             case '2':
  29.                 printf("O RG começa com qual número? \n");
  30.                 num = (getchar()- '0');
  31.                 findRG(num);
  32.                 break;
  33.             case '0':
  34.                 printf("Finalizando \n");
  35.                 break;
  36.             default:
  37.                 printf("Digite uma opção válida \n");
  38.                 break;
  39.         }
  40.         printf("\n");
  41.     }
  42.  
  43.     system("pause");
  44.     return 0;
  45. }
  46.  
  47. char options(){
  48.     int opt;
  49.     printf("Escolha uma opção: \n");
  50.     printf("1 - Digitar um RG \n");
  51.     printf("2 - Encontrar um RG \n");
  52.     printf("0 - SAIR \n");
  53.     opt = getche();
  54.     printf("\n");
  55.     return opt;
  56. }
  57. void readRG(){
  58.     char rg[10];
  59.     int i;
  60.  
  61.     printf("Digite um RG: \t");
  62.     fflush(stdin);
  63.     gets(rg);
  64.  
  65.     for(i=0;i<10;i++)
  66.         listRG[nextRG][i]=rg[i];
  67.  
  68.     if(nextRG<20)
  69.         nextRG = nextRG + 1;
  70.     else
  71.         nextRG = 0;
  72. }
  73. void findRG(int d){
  74.     int i;
  75.     char numStr = d+'0';
  76.  
  77.     for (i=0;i <20;i++){
  78.           if (arr[i][0] == numStr) {
  79.                printf("%s \n", arr[i]);
  80.          }
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement