Guest User

Untitled

a guest
Nov 18th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. \{
  5. FILE *fichero;
  6. char nombre[10] = "datos.dat";
  7. unsigned int i;
  8.  
  9. fichero = fopen( nombre, "w" );
  10. printf( "Fichero: %s (para escritura) -> ", nombre );
  11. if( fichero )
  12. printf( "creado (ABIERTO)\n" );
  13. else
  14. \{
  15. printf( "Error (NO ABIERTO)\n" );
  16. return 1;
  17. }
  18.  
  19. fprintf( fichero, "Esto es un ejemplo de usar la funcion \'fprintf\'\n" );
  20. fprintf( fichero, "\t 2\t 3\t 4\n" );
  21. fprintf( fichero, "x\tx\tx\tx\n\n" );
  22. for( i=1; i<=10; i++ )
  23. fprintf( fichero, "%d\t%d\t%d\t%d\n", i, i*i, i*i*i, i*i*i*i );
  24.  
  25. fprintf( stdout, "Datos guardados en el fichero: %s\n", nombre );
  26. if( !fclose(fichero) )
  27. printf( "Fichero cerrado\n" );
  28. else
  29. \{
  30. printf( "Error: fichero NO CERRADO\n" );
  31. return 1;
  32. }
  33.  
  34. return 0;
  35. }
Add Comment
Please, Sign In to add comment