xandyrj Postado Dezembro 18, 2012 Denunciar Share Postado Dezembro 18, 2012 #include <string.h>#include <stdio.h>#include <stdlib.h>#include <conio.h>#define TAMMAXREG 500000int main(void){ FILE *fp,*fb; char string [512]; int tamreg, tamarq; /* abrir o arquivo */ fp = fopen("DEMO.DAT", "r+b"); if (fp == NULL) { printf("\nERRO na abertura do arquivo.\n"); exit(1); } /* ler a string */ if (fgets(string, TAMMAXREG, fp) == NULL) { printf("\nERRO na leitura do arquivo.\n"); exit(1); } tamreg = strlen(string); if (fseek(fp, 0, SEEK_END) != 0) { printf("\nERRO no fseek.\n"); exit(1); } tamarq= ftell(fp); if (tamarq == -1) { printf("\nERRO no ftell.\n"); exit(1); } fb = fopen ("teste.saida","w+b"); if (fb==NULL) { printf("\nERRO no arquivo de saida.\n"); exit(1); } if (fseek(fp, 0, SEEK_SET) != 0) { printf("\nERRO no fseek.\n"); exit(1); } if (fread(string,1,tamreg,fp)!=tamreg) { printf("\nERRO\n"); exit(1); } if (fwrite(string,1,tamreg,fb)!=tamreg) { printf("\nERRO\n"); exit(1); } if (fseek(fp,5*tamreg,SEEK_SET)!=0) { printf("\nERRO no fseek.\n"); exit(1); } if (fread (string,1,tamreg,fp)!=tamreg) { printf("\nERRO\n"); exit(1); } if (fwrite(string,1,tamreg,fb)!=tamreg) { printf("\nERRO\n"); exit(1); } if (fseek(fp,1*tamreg,SEEK_SET)!=0) { printf("\nERRO no fseek.\n"); exit(1); } if (fread (string,1,tamreg,fp)!=tamreg) { printf("\nERRO\n"); exit(1); } if (fwrite(string,1,tamreg,fb)!=tamreg) { printf("\nERRO\n"); exit(1); } if (fseek(fp,6*tamreg,SEEK_SET)!=0) { printf("\nERRO no fseek.\n"); exit(1); } if (fread (string,1,tamreg,fp)!=tamreg) { printf("\nERRO\n"); exit(1); } if (fwrite(string,1,tamreg,fb)!=tamreg) { printf("\nERRO\n"); exit(1); } if (fseek(fp,2*tamreg,SEEK_SET)!=0) { printf("\nERRO no fseek.\n"); exit(1); } if (fread (string,1,tamreg,fp)!=tamreg) { printf("\nERRO\n"); exit(1); } if (fwrite(string,1,tamreg,fb)!=tamreg) { printf("\nERRO\n"); exit(1); } if (fseek(fp,7*tamreg,SEEK_SET)!=0) { printf("\nERRO no fseek.\n"); exit(1); } if (fread (string,1,tamreg,fp)!=tamreg) { printf("\nERRO\n"); exit(1); } if (fwrite(string,1,tamreg,fb)!=tamreg) { printf("\nERRO\n"); exit(1); } if (fseek(fp,3*tamreg,SEEK_SET)!=0) { printf("\nERRO no fseek.\n"); exit(1); } if (fread (string,1,tamreg,fp)!=tamreg) { printf("\nERRO\n"); exit(1); } if (fwrite(string,1,tamreg,fb)!=tamreg) { printf("\nERRO\n"); exit(1); } if (fseek(fp,8*tamreg,SEEK_SET)!=0) { printf("\nERRO no fseek.\n"); exit(1); } if (fread (string,1,tamreg,fp)!=tamreg) { printf("\nERRO\n"); exit(1); } if (fwrite(string,1,tamreg,fb)!=tamreg) { printf("\nERRO\n"); exit(1); } if (fseek(fp,4*tamreg,SEEK_SET)!=0) { printf("\nERRO no fseek.\n"); exit(1); } if (fread (string,1,tamreg,fp)!=tamreg) { printf("\nERRO\n"); exit(1); } if (fwrite(string,1,tamreg,fb)!=tamreg) { printf("\nERRO\n"); exit(1); } if (fseek(fp,9*tamreg,SEEK_SET)!=0) { printf("\nERRO no fseek.\n"); exit(1); } if (fread (string,1,tamreg,fp)!=tamreg) { printf("\nERRO\n"); exit(1); } if (fwrite(string,1,tamreg,fb)!=tamreg) { printf("\nERRO\n"); exit(1); } /* display the string */ printf("tamreg = %d\n", tamreg); printf("registro = %s\n", string); printf("tamarq = %d\n", tamarq); fclose(fp); fclose(fb); getch();} Citar Link para o comentário Compartilhar em outros sites More sharing options...
Pergunta
xandyrj
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define TAMMAXREG 500000
int main(void)
{
FILE *fp,*fb;
char string [512];
int tamreg, tamarq;
/* abrir o arquivo */
fp = fopen("DEMO.DAT", "r+b");
if (fp == NULL)
{
printf("\nERRO na abertura do arquivo.\n");
exit(1);
}
/* ler a string */
if (fgets(string, TAMMAXREG, fp) == NULL)
{
printf("\nERRO na leitura do arquivo.\n");
exit(1);
}
tamreg = strlen(string);
if (fseek(fp, 0, SEEK_END) != 0)
{
printf("\nERRO no fseek.\n");
exit(1);
}
tamarq= ftell(fp);
if (tamarq == -1)
{
printf("\nERRO no ftell.\n");
exit(1);
}
fb = fopen ("teste.saida","w+b");
if (fb==NULL)
{
printf("\nERRO no arquivo de saida.\n");
exit(1);
}
if (fseek(fp, 0, SEEK_SET) != 0)
{
printf("\nERRO no fseek.\n");
exit(1);
}
if (fread(string,1,tamreg,fp)!=tamreg)
{
printf("\nERRO\n");
exit(1);
}
if (fwrite(string,1,tamreg,fb)!=tamreg)
{
printf("\nERRO\n");
exit(1);
}
if (fseek(fp,5*tamreg,SEEK_SET)!=0)
{
printf("\nERRO no fseek.\n");
exit(1);
}
if (fread (string,1,tamreg,fp)!=tamreg)
{
printf("\nERRO\n");
exit(1);
}
if (fwrite(string,1,tamreg,fb)!=tamreg)
{
printf("\nERRO\n");
exit(1);
}
if (fseek(fp,1*tamreg,SEEK_SET)!=0)
{
printf("\nERRO no fseek.\n");
exit(1);
}
if (fread (string,1,tamreg,fp)!=tamreg)
{
printf("\nERRO\n");
exit(1);
}
if (fwrite(string,1,tamreg,fb)!=tamreg)
{
printf("\nERRO\n");
exit(1);
}
if (fseek(fp,6*tamreg,SEEK_SET)!=0)
{
printf("\nERRO no fseek.\n");
exit(1);
}
if (fread (string,1,tamreg,fp)!=tamreg)
{
printf("\nERRO\n");
exit(1);
}
if (fwrite(string,1,tamreg,fb)!=tamreg)
{
printf("\nERRO\n");
exit(1);
}
if (fseek(fp,2*tamreg,SEEK_SET)!=0)
{
printf("\nERRO no fseek.\n");
exit(1);
}
if (fread (string,1,tamreg,fp)!=tamreg)
{
printf("\nERRO\n");
exit(1);
}
if (fwrite(string,1,tamreg,fb)!=tamreg)
{
printf("\nERRO\n");
exit(1);
}
if (fseek(fp,7*tamreg,SEEK_SET)!=0)
{
printf("\nERRO no fseek.\n");
exit(1);
}
if (fread (string,1,tamreg,fp)!=tamreg)
{
printf("\nERRO\n");
exit(1);
}
if (fwrite(string,1,tamreg,fb)!=tamreg)
{
printf("\nERRO\n");
exit(1);
}
if (fseek(fp,3*tamreg,SEEK_SET)!=0)
{
printf("\nERRO no fseek.\n");
exit(1);
}
if (fread (string,1,tamreg,fp)!=tamreg)
{
printf("\nERRO\n");
exit(1);
}
if (fwrite(string,1,tamreg,fb)!=tamreg)
{
printf("\nERRO\n");
exit(1);
}
if (fseek(fp,8*tamreg,SEEK_SET)!=0)
{
printf("\nERRO no fseek.\n");
exit(1);
}
if (fread (string,1,tamreg,fp)!=tamreg)
{
printf("\nERRO\n");
exit(1);
}
if (fwrite(string,1,tamreg,fb)!=tamreg)
{
printf("\nERRO\n");
exit(1);
}
if (fseek(fp,4*tamreg,SEEK_SET)!=0)
{
printf("\nERRO no fseek.\n");
exit(1);
}
if (fread (string,1,tamreg,fp)!=tamreg)
{
printf("\nERRO\n");
exit(1);
}
if (fwrite(string,1,tamreg,fb)!=tamreg)
{
printf("\nERRO\n");
exit(1);
}
if (fseek(fp,9*tamreg,SEEK_SET)!=0)
{
printf("\nERRO no fseek.\n");
exit(1);
}
if (fread (string,1,tamreg,fp)!=tamreg)
{
printf("\nERRO\n");
exit(1);
}
if (fwrite(string,1,tamreg,fb)!=tamreg)
{
printf("\nERRO\n");
exit(1);
}
/* display the string */
printf("tamreg = %d\n", tamreg);
printf("registro = %s\n", string);
printf("tamarq = %d\n", tamarq);
fclose(fp);
fclose(fb);
getch();
}
Link para o comentário
Compartilhar em outros sites
0 respostass a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.