/************************************************/
/* soubor IO-DP01.C				*/
/* vytvori  textovy soubor SOUBOR.TXT		*/
/* verze se streamem				*/
/************************************************/

#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#include <process.h>
#include <string.h>
#include <sys\stat.h>

int chyba(int er)
{
 extern int errno;
 if (er != 0)
   {
    perror(strerror(errno));	/* zapise chybove hlaseni do stderr */
    exit(errno);		/* -> DOS; ukonci chod programu	    */
   }
 return er;
} /* int chyba(void) */

int main(void)
{
 FILE *soubor;
 int i;
 char *s, *jmeno = "soubor.txt";

 if ((soubor = fopen(jmeno, "wt")) == NULL)
	 chyba(1);

 s = "Toto je textovy soubor vytvoreny v C.\n"
		 "pristup pomoci proudu - FILE *\n";
 fputs(s, soubor);
 for (i = 1; i < 10; i++)
	 {
		fprintf(soubor, "%5d", i);
	 } /* for (i = 1; i < 10; i++) */

 fputs("\n\n", soubor);

 s = "Uz to umim!\n";
 fputs(s, soubor);

 s = "Jeste pridat posledni radek na konec.";
 fputs(s, soubor);


 if (fclose(soubor) == EOF)
	 chyba(1);

 return 0;
} /* int main(void) */