Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //escrever, ps: escreve por cima
- #include <stdio.h>
- int main(void){
- FILE *file;
- file = fopen("teste.txt","w");
- fprintf(file,"texto");
- fclose(file);
- return 0;
- }
- //ler dados
- #include <stdio.h>
- #include <stdlib.h>
- int main(void){
- FILE *file;
- file = fopen("teste.txt","r");
- if(file == NULL){
- printf("Arquivo nao pode ser aberto\n");
- system("pause");
- return 0; //sair do programa
- }
- int x, y, z;
- //capturar jeito 1
- /* fscanf(file,"%i %i %i", &x, &y, &z); //%i indica que é int
- printf("%i %i %i\n", x, y, z); */
- //capturar jeito 2
- char frase[100];
- while(fgets(frase, 100, file) != NULL){
- printf("%s", frase);
- }
- fclose(file);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment