Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- #include<math.h>
- char peganumeros(int*, int);
- char peganome1(char*);
- char peganome2(char*);
- int main(){
- FILE *matricula;
- FILE *nome;
- FILE *senha;
- char nome1[20], nome2[20], letras[3], letrasfinais[3];
- int mat[10];
- int resposta, i=0, n = 0;
- matricula = fopen("alunos.matricula.txt", "r");
- nome = fopen("alunos.nome.txt", "r");
- senha = fopen("arquivosenha.txt", "w");
- while(!feof(nome)){
- fscanf(nome,"%s", &nome1);
- fscanf(nome,"%s", &nome2);
- *letras =peganome1(nome1);
- *letrasfinais=peganome2(nome2);
- printf("nome: %s", nome1);
- printf(" sobrenome: %s \n\n", nome2);
- }
- while(!feof(matricula)){
- fscanf(matricula,"%d", &mat[n]);
- printf("matricula: %d \n", mat[n]);
- n++;
- }
- for(i = 0; i < n; i++ ){
- resposta=peganumeros(mat,i);
- }
- fclose(matricula);
- fclose(nome);
- return 0;
- }
- char peganumeros(int *matricula, int n){
- int a,resto,divisor,i = 0,resposta, b;
- char inverte[10];
- a=matricula[n];
- while(matricula[n] > 0){
- matricula[n]=matricula[n]/10;
- i++;
- }
- matricula[n]=a;
- resto = matricula[n]%100000;
- divisor = matricula[n]/pow(10,i-2);
- resposta=resto/divisor;
- i=0;
- b=resposta;
- while(resposta > 0){
- resposta = resposta/10;
- i++;
- }
- resposta=b;
- if(i<4){
- resposta= resposta*pow(10,4-i);
- for(i = 1; i < 4; i++){
- inverte[i]=resposta%10;
- }
- printf("%s",inverte);
- }
- if(divisor==0)
- resposta=0;
- printf("\nresto = %d divisor = %d resposta = %d\n", resto, divisor, resposta);
- }
- char peganome1(char *nome){
- int tamanho = 0, i = 0;
- char letras[3];
- for(i=0;i<3;i++){
- letras[i]= nome[i];
- }
- printf("as 3 primeiras letras: %s ", letras);
- return *letras;
- }
- char peganome2(char *nome2){
- int tamanho = strlen(nome2), i = 0, j=0;
- char letras[3];
- for(i=tamanho-3, j = 0; i< tamanho, j < 3; i++, j++){
- letras[j]=nome2[i];
- }
- printf("as 3 ultimas letras: %s ", letras);
- return *letras;
- }
Add Comment
Please, Sign In to add comment