Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- /* run this program using the console pauser or add your own getch, system("pause") or input loop */
- int main() {
- FILE *archivo, *archivoLec; //declaramos la variable 'archivo' como FILE
- char buff[255];
- //ESCRITURA
- archivo = fopen("test.txt", "w"); //asociamos test.txt a la variable 'archivo'
- fprintf(archivo, "Harry es profesor\n");
- fputs("Una sola vuelta\n", archivo);
- fclose(archivo); //cerrar archivo
- //LECTURA
- archivoLec = fopen("test.txt", "r"); //abre archivo de escritura
- fscanf(archivoLec, "%s", buff); //lee la cadena de caracteres hasta el espacio
- printf("%s\n", buff );
- fgets(buff, 255, (FILE*)archivoLec); //lee la cadena de caracteres hasta el eol(final del la linea)
- printf("%s\n", buff );
- fgets(buff, 255, (FILE*)archivoLec); //lee la cadena de caracteres hasta el eol(final del la linea)
- printf("%s\n", buff );
- return 0;
- }
Add Comment
Please, Sign In to add comment