Jump to content
Fórum Script Brasil
  • 0

Pesquisar arquivo txt em C


Thiago Balthazar

Question

Olá ..

preciso de ajuda neste codigo. O objetivo era criar um arquivo txt e depois ler ele. a parte de criar tá rodando, mas a parte de pesquisar tá dando erro. Me ajuda plz..

codigo:

#include <stdio.h>
 #include <stdlib.h>

 void CriarBloco();
 void LerBloco();


 int op, n;
 char bloco[33];
 FILE *pt;

 int main(int argc, char *argv[])
 {
 printf("\t----SISTEMA DE ARQUIVOS----\n");
 printf(" 1 - CRIAR BLOCO\n");
 printf(" 2 - LER BLOCO\n");
 printf("OPCAO: "); scanf("%d", &op);
 system("cls");

switch (op)
 {
 case 1 : CriarBloco();
 break;

 case 2 : LerBloco();
 break;
 }
 return 0;
 }


 void CriarBloco()
 {
 printf("INFORME O BLOCO A SER GRAVADO: "); scanf("%i", &n);
 printf("INFORME O CONTEUDO DO BLOCO: "); scanf("%s", &bloco);

 pt=fopen("Sistema de Arquivos.txt","a");
 if (pt == NULL)
 {
 printf("Erro de Abertura!!!");
 }

 fprintf(pt,"----------------------------------\n");
 fprintf(pt," BLOCOS\n");
 fprintf(pt,"----------------------------------\n");
 fprintf(pt,"%i - %s\n", n, bloco);
 fclose(pt);
 }
 void LerBloco()
 {
 pt=fopen("Sistema de Arquivos.txt","rt");
 if (pt == NULL)
 {
 printf("Erro de Abertura!!!");
 }

 while (!(feof (pt)))
 {
 printf("INFORME O BLOCO A SER LIDO: "); scanf("%i", &n);
 printf("%i - %s", n, bloco);//Não estou conseguindo trazer o bloco lido
 }

 fclose(pt);



 }

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
      152.2k
    • Total Posts
      652k
×
×
  • Create New...