Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- #include<conio.h>
- int main(){
- FILE *arq_exc2;
- FILE *arq_M;
- FILE *arq_F;
- int i,j, cont=1,tamanho,pos=43, tM, tF;
- char M[500], F[500]; //sexo = posição 31
- char aux[32], auxM[32], auxF[32];
- float a,b, aF, bF, aM, bM;
- arq_exc2 = fopen("EXC2.txt", "a+");
- if(arq_exc2==NULL){
- printf("ERRO de abertura de arquivo\n");
- }
- else{
- strcpy(aux,"");
- strcpy(M,"");
- strcpy(F,"");
- while(fscanf(arq_exc2, " %s %f %f", &aux, &a, &b) != EOF){
- //printf("\n %s %f %f ", aux, a, b);
- if (aux[30] == 'M'){
- printf("\nMasculino");
- arq_M = fopen("arqM.txt", "a+b");
- fwrite(&aux, sizeof(char), 32,arq_M);
- fwrite(&a, sizeof(float), 1, arq_M);
- fwrite(&b, sizeof(float), 1, arq_M);
- fclose(arq_M);
- }
- else if(aux[30] == 'F'){
- printf("\nFeminino");
- arq_F = fopen("arqF.txt", "a+b");
- fwrite(&aux, sizeof(char), 32,arq_F);
- fwrite(&a, sizeof(float), 1, arq_F);
- fwrite(&b, sizeof(float), 1, arq_F);
- fclose(arq_F);
- }
- }
- //system("pause");
- //system("arqF.txt");
- //system("pause");
- //system("arqM.txt");
- system("pause");
- fclose(arq_exc2);
- arq_M = fopen("arqM.txt", "rb");
- fread(&auxM, sizeof(char), 32,arq_M);
- fread(&aM, sizeof(float), 1,arq_M);
- fread(&bM, sizeof(float), 1,arq_M);
- fclose(arq_M);
- printf("\n%s\n", auxM);
- printf("%.3f\n", aM);
- printf("%.3f\n", bM);
- system("pause");
- /* EXEMPLO DE FTELL
- printf("\n byte = %d ", ftell(arq_exc2));
- char m[43];
- fseek(arq_exc2, 0, SEEK_SET);
- fread(aux, sizeof(char), 43, arq_exc2);
- printf("\n M = %s \n", m);
- printf("\n byte = %d ", ftell(arq_exc2));
- system("pause");
- */
- //------------------------------------------------------------------------------------
- /*
- fread(aux, sizeof(char), 500,arq_exc2); //aqui copia todos os dados do arquivo para a string aux
- printf("%s", aux);
- fclose(arq_exc2);
- tamanho = strlen(aux);
- tamanho=tamanho/45;
- printf("\n\nTAMANHO %d\n", tamanho);
- if(aux[30]=='M'){
- for(j=0;j<43;j++){
- M[j]=aux[j];
- printf("%c", M[j]);
- }
- }
- else if(aux[30]=='F'){
- for(j=0;j<43;j++){
- F[j]=aux[j];
- printf("%c", F[j]);
- }
- }
- for(i=0;i<tamanho-1;i++){
- printf("\ni:%d\n", i);
- if(aux[pos+30]=='M'){
- printf("\npos M: %d\n", pos);
- for(j=pos;j<pos+43;j++){
- M[j]=aux[j];
- printf("%c", M[j]);
- }
- cont++;
- //pos=pos*cont;printf("M: %s", M); //aqui o M tem a primeira linha do sexo masculino
- printf("F: %s", F);
- printf("\npos M depois do cont: %d\n", pos);
- getch();
- }
- else if(aux[pos+30]=='F'){
- printf("\npos F: %d\n", pos);
- for(j=pos;j<pos+43;j++){
- F[j]=aux[j];
- printf("%c", F[j]);
- }
- cont++;
- pos=pos*cont; fclose(arq_exc2);
- printf("\npos F depois do cont: %d\n", pos);
- }
- }//fim do for que roda o tanto de linhas que tem -1
- tM = strlen(M);
- printf("\n\ntM: %d", tM);
- tF = strlen(F);
- printf("\ntF: %d", tF);
- printf("\n\n");
- printf("M: %s", M); //aqui o M tem a primeira linha do sexo masculino
- printf("F: %s", F);
- */
- }//fim do else se o arquivp abrir
- //system("pause");
- //system("EXC2.txt");
- return 0;
- }
- //a parte de conferencia esta certa para a primeira linha, o M contem a primeira linha da string aux (que tem o conteudo do txt)
- //agora falta fazer para conferir a string aux toda e pegar todas as linhas do F e M
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement