danim

Arquivos C

Sep 5th, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. //escrever, ps: escreve por cima
  2. #include <stdio.h>
  3.  
  4. int main(void){
  5.     FILE *file;
  6.     file = fopen("teste.txt","w");
  7.     fprintf(file,"texto");
  8.     fclose(file);
  9. return 0;
  10. }
  11.  
  12. //ler dados
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15.  
  16. int main(void){
  17.     FILE *file;
  18.     file = fopen("teste.txt","r");
  19.     if(file == NULL){
  20.         printf("Arquivo nao pode ser aberto\n");
  21.         system("pause");
  22.         return 0; //sair do programa
  23.     }
  24.     int x, y, z;
  25.     //capturar jeito 1
  26.     /* fscanf(file,"%i %i %i", &x, &y, &z); //%i indica que é int
  27.     printf("%i %i %i\n", x, y, z); */
  28.     //capturar jeito 2
  29.     char frase[100];
  30.     while(fgets(frase, 100, file) != NULL){
  31.         printf("%s", frase);
  32.     }
  33. fclose(file);
  34. system("pause");
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment