Advertisement
gtw7375

Manipulação de Arquivos - Leitura e criação de arquivo

Dec 4th, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.53 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. main(){
  4.    
  5.     FILE *arq_teste, *arq_testeW;
  6.    
  7.     char n, r;
  8.     arq_teste = fopen("teste.txt", "r");
  9.     arq_testeW = fopen("teste2.txt", "w+b");
  10.    
  11.     if(arq_teste == NULL){
  12.        
  13.         printf("Erra na abertura do arquivo teste.txt.\n/");
  14.         system("pause");
  15.         exit(-1);
  16.     }
  17.    
  18.     while(!feof(arq_teste)){
  19.        
  20.         fscanf(arq_teste, "%c", &n);  printf("%c\n", n);
  21.        
  22.         r = fprintf(arq_testeW, "Valor: %d \n", n);
  23.        
  24.         if(r==EOF) {
  25.             printf("Erro na gravacao!\n");
  26.         }
  27.     }
  28.    
  29.     fclose(arq_teste);
  30.     system("pause");
  31.    
  32.    
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement