Jump to content
Fórum Script Brasil
  • 0

Como criar um loop para esse programa?


xandyrj

Question

#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 to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152k
    • Total Posts
      651.5k
×
×
  • Create New...