Last active
August 29, 2015 14:25
-
-
Save kalimalrazif/2662c9c9f139dd344e90 to your computer and use it in GitHub Desktop.
Escritura en archivo de texto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(){ | |
// La variable de archivo | |
FILE *archivito; | |
// Variable para escribir datos en el archivo | |
char buffer[100] = "Hola Mundo"; | |
// Variable numerica | |
float numero = 3.1416; | |
archivito = fopen("./archivo.txt", "a+"); | |
// Si no podemos abrir el archivo, terminamos el programa | |
if(archivito == NULL) { printf("No se pudo abrir el archivo... \n"); return -1; } | |
fputc('G', archivito); | |
fputc('o', archivito); | |
fputc('l', archivito); | |
fputc('\n', archivito); | |
// La primera linea del archivo fue escrita y contiene la frase Gol\n | |
// Intentemos escribir algo mas, una cadena! | |
// Pero ojo, solo esta escribiendo Hola Mundo, falta el retorno de carro | |
// para completar la linea. | |
fputs(buffer, archivito); | |
// Ahora le toca el turno a fprintf | |
fprintf ("\nEsto es un numero con formato %3.3f\n%3.3f", numero,numero); | |
fclose(archivito); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment