Guest User

Untitled

a guest
Apr 22nd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.35 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. #include<math.h>
  5.  
  6. char peganumeros(int*, int);
  7. char peganome1(char*);
  8. char peganome2(char*);
  9.  
  10. int main(){
  11.  
  12.     FILE *matricula;
  13.     FILE *nome;
  14.     FILE *senha;
  15.     char nome1[20], nome2[20], letras[3], letrasfinais[3];
  16.     int mat[10];
  17.     int resposta, i=0, n = 0;
  18.  
  19.  
  20.  
  21.     matricula = fopen("alunos.matricula.txt", "r");
  22.     nome = fopen("alunos.nome.txt", "r");
  23.     senha = fopen("arquivosenha.txt", "w");
  24.  
  25.  
  26.     while(!feof(nome)){
  27.  
  28.             fscanf(nome,"%s", &nome1);
  29.             fscanf(nome,"%s", &nome2);
  30.  
  31.             *letras =peganome1(nome1);
  32.             *letrasfinais=peganome2(nome2);
  33.  
  34.             printf("nome: %s", nome1);
  35.             printf("  sobrenome: %s \n\n", nome2);
  36.     }
  37.  
  38.      while(!feof(matricula)){
  39.  
  40.             fscanf(matricula,"%d", &mat[n]);
  41.  
  42.             printf("matricula: %d \n", mat[n]);
  43.             n++;
  44.  
  45.     }
  46.  
  47.     for(i = 0; i < n; i++ ){
  48.  
  49.         resposta=peganumeros(mat,i);
  50.     }
  51.  
  52.     fclose(matricula);
  53.     fclose(nome);
  54.  
  55.  return 0;
  56. }
  57.  
  58. char peganumeros(int *matricula, int n){
  59.  
  60.     int a,resto,divisor,i = 0,resposta, b;
  61.     char inverte[10];
  62.  
  63.     a=matricula[n];
  64.  
  65.     while(matricula[n] > 0){
  66.         matricula[n]=matricula[n]/10;
  67.         i++;
  68.     }
  69.  
  70.     matricula[n]=a;
  71.  
  72.     resto = matricula[n]%100000;
  73.     divisor = matricula[n]/pow(10,i-2);
  74.     resposta=resto/divisor;
  75.     i=0;
  76.  
  77.     b=resposta;
  78.     while(resposta > 0){
  79.         resposta = resposta/10;
  80.         i++;
  81.     }
  82.  
  83.     resposta=b;
  84.  
  85.     if(i<4){
  86.         resposta= resposta*pow(10,4-i);
  87.         for(i = 1; i < 4; i++){
  88.  
  89.             inverte[i]=resposta%10;
  90.         }
  91.  
  92.        printf("%s",inverte);
  93.  
  94.     }
  95.  
  96.  
  97.     if(divisor==0)
  98.         resposta=0;
  99.  
  100.  
  101.     printf("\nresto = %d   divisor = %d  resposta = %d\n", resto, divisor, resposta);
  102. }
  103.  
  104. char peganome1(char *nome){
  105.  
  106.     int tamanho = 0, i = 0;
  107.     char letras[3];
  108.  
  109.  
  110.     for(i=0;i<3;i++){
  111.         letras[i]= nome[i];
  112.     }
  113.  
  114.     printf("as 3 primeiras letras: %s   ", letras);
  115.     return *letras;
  116.  
  117. }
  118.  
  119.  
  120.  
  121. char peganome2(char *nome2){
  122.  
  123.     int tamanho = strlen(nome2), i = 0, j=0;
  124.     char letras[3];
  125.  
  126.     for(i=tamanho-3, j = 0; i< tamanho, j < 3; i++, j++){
  127.  
  128.         letras[j]=nome2[i];
  129.  
  130.     }
  131.     printf("as 3 ultimas letras: %s  ", letras);
  132.  
  133.     return *letras;
  134.  
  135. }
Add Comment
Please, Sign In to add comment