Guest User

Untitled

a guest
Feb 21st, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  5.  
  6. int main() {
  7. FILE *archivo, *archivoLec; //declaramos la variable 'archivo' como FILE
  8. char buff[255];
  9. //ESCRITURA
  10. archivo = fopen("test.txt", "w"); //asociamos test.txt a la variable 'archivo'
  11. fprintf(archivo, "Harry es profesor\n");
  12. fputs("Una sola vuelta\n", archivo);
  13. fclose(archivo); //cerrar archivo
  14. //LECTURA
  15. archivoLec = fopen("test.txt", "r"); //abre archivo de escritura
  16. fscanf(archivoLec, "%s", buff); //lee la cadena de caracteres hasta el espacio
  17. printf("%s\n", buff );
  18. fgets(buff, 255, (FILE*)archivoLec); //lee la cadena de caracteres hasta el eol(final del la linea)
  19. printf("%s\n", buff );
  20. fgets(buff, 255, (FILE*)archivoLec); //lee la cadena de caracteres hasta el eol(final del la linea)
  21. printf("%s\n", buff );
  22. return 0;
  23. }
Add Comment
Please, Sign In to add comment